Oracle-switchover转换DG角色

switchover 切换过程

primary库进行switchover切换

运行切换条件检查(12.1+)

ALTER DATABASE SWITCHOVER TO <standby db_unique_name> VERIFY;

检查主库状态信息

主库switchover_status显示 "TO STANDBY",即表示主库此时可以切换为备库

set lines 168 pages 99
col name for a18
col db_unique_name for a18
col open_mode for a24
col log_mode for a12
col database_role for a20
col host_name for a20
col flashback_on for a16
col switchover_status for a28

select name,db_unique_name,open_mode,log_mode,database_role,(select HOST_NAME from v$instance) HOST_NAME,flashback_on,switchover_status from v$database;

手动运行switchover切换

-- alter database commit to switchover to physical standby with session shutdown; 
   alter database commit to switchover to standby with session shutdown;

此时,数据库关闭

启动数据库

startup;

检查数据库状态

set lines 168 pages 99
col name for a18
col db_unique_name for a18
col open_mode for a24
col log_mode for a12
col database_role for a20
col host_name for a20
col flashback_on for a16
col switchover_status for a28

select name,db_unique_name,open_mode,log_mode,database_role,(select HOST_NAME from v$instance) HOST_NAME,flashback_on,switchover_status from v$database;

此时,数据库以PHYSICAL STANDBY角色运行

standby库进行switchover切换

检查当前数据库信息

set lines 168 pages 99
col name for a18
col db_unique_name for a18
col open_mode for a24
col log_mode for a12
col database_role for a20
col host_name for a20
col flashback_on for a16
col switchover_status for a28

select name,db_unique_name,open_mode,log_mode,database_role,(select HOST_NAME from v$instance) HOST_NAME,flashback_on,switchover_status from v$database;

确认SWITCHOVER_STATUS 状态为:TO PRIMARY

手动执行切换

 alter database commit to switchover to primary with session shutdown;

检查数据库状态信息

set lines 168 pages 99
col name for a18
col db_unique_name for a18
col open_mode for a24
col log_mode for a12
col database_role for a20
col host_name for a20
col flashback_on for a16
col switchover_status for a28

select name,db_unique_name,open_mode,log_mode,database_role,(select HOST_NAME from v$instance) HOST_NAME,flashback_on,switchover_status from v$database;

打开数据库

alter database open;

新备库(即原主库)开始日志应用

 alter database recover managed standby database using current logfile disconnect from session;

检查DG状态

SELECT CLIENT_PROCESS, PROCESS, THREAD#, SEQUENCE#, STATUS 
FROM V$MANAGED_STANDBY 
WHERE CLIENT_PROCESS='LGWR' OR PROCESS='MRP0';

注意事项

  • alter database commit to switchover to physical standby with session shutdown; 等待数据库挂掉(only shutdown abort)后再启动到mount
  • 在 RAC 环境不需要关闭其他的实例,执行 Switchover 的命令会关闭所有的实例
原文地址:https://www.cnblogs.com/binliubiao/p/15148538.html