欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

DataGuard角色切换

程序员文章站 2024-01-16 13:51:28
...

Step 1 Verify that the primary database can be switched to the standby role.验证主库能够切换到备用角色。SELECT SWITCHO

Step 1 Verify that the primary database can be switched to the standby role.
验证主库能够切换到备用角色。
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
idle>:wq

SWITCHOVER_STATUS
--------------------
TO STANDBY

Step 2 Initiate the switchover on the primary database.
在主库上面开始切换
alter database commit to switchover to physical standby with session shutdown ;

Step 3 Shut down and then mount the former primary database.
关闭并且mount上从前的主库。

shutdown abort;
startup mount ;

Step 4 Verify that the switchover target is ready to be switched to the primary role.
验证转换目标已经准备好转换为主库角色
SWITCHOVER_STATUS
--------------------
SWITCHOVER LATENT

这里查询出来的值不为TO_PRIMARY即有点问题。
执行下一步的时候可能会出现问题。

Step 5 Switch the target physical standby database role to the primary role.
转换目标逻辑备用库角色为主库角色。

sys@DEX> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN
*
ERROR at line 1:
ORA-16139: media recovery required

这里提示需要介质恢复。

sys@DEX> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

sys@DEX> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
TO PRIMARY

sys@DEX> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

Database altered.

Step 6 Open the new primary database.
打开新的主库
sys@DEX> ALTER DATABASE OPEN;

Database altered.

Step 7 Verify the switch role .
验证角色转换

主库执行
sys@DEX> alter system switch logfile ;

System altered.


sys@DEX> select sequence# from v$log ;


SEQUENCE#
----------
40
41
42


sys@DEX>

standby库执行

sys@DEX> select sequence# from v$log ;

SEQUENCE#
----------
40
42
41


sys@DEX>

DataGuard角色切换