1. switchover操作
1.1 备库先关闭实时日志应用
standby>alter database recover managed standby database cancel;
1.2 主库先判断是否可以支持switchover操作
primary> select switchover_status from v$database;
该值为:TO STANDBY;表示支持。
该值为:SESSION ACTIVE;表示主库有激活会话。不妨碍switchover操作。1.3 启动switchover;主库转换physical standby。
若上值为第二种情况;后面需加 with shutdown session
即 alter database commit to switchover to physical standby with shutdown session;primary> alter database commit to switchover to physical standby;Database altered.
1.4 重启原primary库
Primary> shutdown immediate;ORA- 01507 : database not mountedORACLE instance shut down.Primary> startupORACLE instance started.Total System Global Area 1.5132E+10 bytesFixed Size 2243112 bytesVariable Size 2013267416 bytesDatabase Buffers 1.3086E+10 bytesRedo Buffers 30552064 bytesDatabase mounted.Database opened.
1.5 物理standby切换为primary
standby>alter database commit to switchover to primary;alter database commit to switchover to primary*ERROR at line 1:ORA-16139: media recovery requiredstandby>alter database recover managed standby database disconnect from session;Database altered.standby>alter database commit to switchover to primary;Database altered.
1.6 重启新primary
standby> alter database open;Database altered.
1.7 新physical standby启动实时日志应用
Primary> alter database recover managed standby database using current logfile disconnect from session;
2.failover操作
模拟主库挂掉
Primary> shutdown abort;ORACLE instance shut down.
2.1 检查归档文件是否连续
查询待转换standby 数据库的V$ARCHIVE_GAP 视图,确认归档文件是否连接
StandBy> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP; no rows selected
如果有,则拷贝过来;
手工的注册这些日志: StandBy> ALTER DATABASE REGISTER LOGFILE '路径';2.2 启动failover,备库切换主库操作。
StandBy> alter database recover managed standby database finish force;Database altered.StandBy> alter database commit to switchover to primary;Database altered.StandBy> alter database open;Database altered.
2.3 将原primary库重建备库操作
参考博客:http://www.cnblogs.com/lottu/p/7054731.html;http://www.cnblogs.com/lottu/p/7058774.html
实施数据库克隆(辅助实例启动到nomount状态后)
应用redo日志操作;或者 启动实时应用redo日志操作。
参考文献:《三思笔记第10.2.4章节》