本文主要是介绍DG主备切换,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ADG
做(switchover
)切换测试
--primary
做如下操作
一定要配置静态监听(略),要不然没有办法同步
主库切换到备库
select database_role,switchover_status,open_mode from v$database;DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE
---------------- -------------------- --------------------
PRIMARY SESSIONS ACTIVE READ WRITE
--主库显示to standby /primary ,如果显示session active 表示有活动会话,需要关闭
备库显示not allowd alter database commit to switchover to physical standby with session shutdown;
startup mount;
备库切换到主库
alter database commit to switchover to primary;
alter database open;
sqlplus / as sysdba
select database_role,switchover_status,open_mode from v$database;DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE
---------------- -------------------- --------------------
PRIMARY TO STANDBY READ WRITE
alter system switch logfile;
archive log list;
Current log sequence 59
新的备库开启实时应用日志
sqlplus / as sysdba
alter database recover managed standby database using current logfile disconnect from session;select database_role,switchover_status,open_mode from v$database;DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE
---------------- -------------------- --------------------
PHYSICAL STANDBY TO PRIMARY READ WRITEarchive log list;
Current log sequence 59
主备切换的过程中要是涉及到RAC
,就要关闭其他实例,只保留一个实例再做切换
破坏主备关系,使主备都是独立的数据库
备库停止同步
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
将备库转为主库
1)强制完成日志应用
SQL > ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;
- 将备库切换为新的主库
SQL > alter database commit to switchover to primary with session shutdown;
注:此时可能报错,如果没有报错,直接alter database open
就可用,如果报介质需要recovery
,继续下面步骤:
3) 备库recover
介质恢复
SQL > recover standby database until cancel;
- 使用
ACTIVATE STANDBY DATABASE
激活备库
alter database activate standby database;
- 打开数据库
alter database open;
至此failover
切换已完成,现在主备都是独立的数据库,主备关系已被破坏。
这篇关于DG主备切换的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!