DG主库和备库之间角色切换
2018-06-22配置DataGuard就是为了主库和备库之间角色切换。
1 主库切换为备库
alter database commit to switchover to physical standby;
ORA-16455: switchover to standby failed
alter database commit to switchover to physical standby with session shutdown;-- 主库有会话连接的时候
shutdown immediate
startup nomount;
alter database mount standby database;
alter database recover managed standby database disconnect from session;
主库
select switchover_status from v$database;
SESSIONS ACTIVE ----------有活动会话。
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
报错ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
2 从库切换为主库
ORA-16139: media recovery required
可能是由于未应用日志引起,解决办法,只需在备库上开启日志应用即可:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
SQL> alter database open;
alter database commit to switchover to primary;
shutdown immediate;
startup
alter system switch logfile;
备库:
--NOT ALLOWED/或者--RECOVERY NEEDED--可能需要恢复或者退出恢复模式。
alter database recover managed standby database disconnect from session;
TO PRIMARY/TO STANDBY显示可以转换
可以执行alter database commit to switchover to primary;
resovable gap
ALTER SYSTEM FLUSH REDO TO ‘db_unique_name’;
SWITCHOVER LATENT
3、最顺利的情况:分别在主备库执行
备库SQL> alter database commit to switchover to primary;
主库SQL> alter database commit to switchover to standby;
select * from v$archive_processes;
分类:数据库 | 标签: dataguard、dg |