Oracle data guard 主库备库切换演练

时间:2022-01-28 16:16:39

本实验做的是将primary主库和standby 备库进行切换演练

步骤如下: 
1 在主库端检查数据库可切换状态

SQL> select switchover_status from v$database;
 
 
  • 1
  • 1

SWITCHOVER_STATUS–>TO STANDBY,表示可以正常切换. 
SWITCHOVER_STATUS–>SESSIONS ACTIVE,表示当前有会话处于ACTIVE状态

2 开始主库正常切换 
如果SWITCHOVER_STATUS 的值为TO STANDBY:

SQL> alter database commit to switchover to physical standby;
 
 
  • 1
  • 1

如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE:

SQL> alter database commit to switchover to physical standby with session shutdown;
 
 
  • 1
  • 1

3 重启主库

SQL> shutdown abort;
SQL> startup mount;
  • 1
  • 2
  • 1
  • 2

4 到备库验证可切换状态

SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
-----------------
TO_PRIMARY
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

5 将目标备库转换为主库 
如果SWITCHOVER_STATUS 的值为TO STANDBY 则:

SQL> alter database commit to switchover to primary;
 
 
  • 1
  • 1

如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE 则:

SQL> alter database commit to switchover to primary with session shutdown;
 
 
  • 1
  • 1

6 打开目标备库

SQL> alter database open;
 
 
  • 1
  • 1

7 开始在目标备库应用日志

SQL> alter database recover managed standby database disconnect;
 
 
  • 1
  • 1

8 检查主备库角色状态:

SQL> select switchover_status,database_role from v$database;