Data Guard 主备库角色转换

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Data Guard 主备库角色转换相关的知识,希望对你有一定的参考价值。

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 mounted
ORACLE instance shut down.
Primary> startup
ORACLE instance started.

Total System Global Area 1.5132E+10 bytes
Fixed Size            2243112 bytes
Variable Size         2013267416 bytes
Database Buffers     1.3086E+10 bytes
Redo Buffers           30552064 bytes
Database 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 required
standby>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章节》

以上是关于Data Guard 主备库角色转换的主要内容,如果未能解决你的问题,请参考以下文章

Oracle12c Data Guard搭建手册

管理和维护DG

oracle data guard备库备份恢复

oracle data guard备库备份恢复

12cDataGuard物理备库角色切换

12cDataGuard物理备库角色切换