本实验做的是将primary主库和standby 备库进行切换演练
步骤如下:
1 在主库端检查数据库可切换状态
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS–>TO STANDBY,表示可以正常切换.
SWITCHOVER_STATUS–>SESSIONS ACTIVE,表示当前有会话处于ACTIVE状态
2 开始主库正常切换
如果SWITCHOVER_STATUS 的值为TO STANDBY:
SQL> alter database commit to switchover to physical standby;
如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE:
SQL> alter database commit to switchover to physical standby with session shutdown;
3 重启主库
SQL> shutdown abort;
SQL> startup mount;
4 到备库验证可切换状态
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
-----------------
TO_PRIMARY
5 将目标备库转换为主库
如果SWITCHOVER_STATUS 的值为TO STANDBY 则:
SQL> alter database commit to switchover to primary;
如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE 则:
SQL> alter database commit to switchover to primary with session shutdown;
6 打开目标备库
SQL> alter database open;
7 开始在目标备库应用日志
SQL> alter database recover managed standby database disconnect;
8 检查主备库角色状态:
SQL> select switchover_status,database_role from v$database;