DataGuard切换(主库为Rac+备库为Rac)
http://blog.itpub.net/29477587/viewspace-1331121/
前段时间做了一次主备库的切换,大体写下操作步骤和记录,分享下。
环境:
db version:11.2.0.3
主库:两节点的RAC
备库:两节点的RAC
是异地灾备,网络质量不太好。
步骤:
1.检查日志应用情况
standby database(备库检查):
SQL> select thread#,SEQUENCE#,FIRST_TIME,next_time,applied from gv$archived_log order by sequence#; (确定日志都已经应用 )
2. 检查日志传输错误
SQL> SELECT STATUS, GAP_STATUS FROM V$ARCHIVE_DEST_STATUS WHERE DEST_ID = 2;
STATUS GAP_STATUS
--------- ------------------------
VALID NO GAP
3. 评估切换时间 --rac环境下备库只有一个实例可以为open状态。
set linesize 200
SQL> column name format a22
SQL> column value format a16
SQL> column unit format a28
SQL> column time_computed format a25
SQL> select * from v$dataguard_stats;
NAME VALUE UNIT TIME_COMPUTED DATUM_TIME
---------------------- ---------------- ---------------------------- ------------------------- ------------------------------
transport lag +00 01:47:32 day(2) to second(0) interval 10/29/2014 10:48:15 10/29/2014 10:47:58
apply lag +00 01:47:32 day(2) to second(0) interval 10/29/2014 10:48:15 10/29/2014 10:47:58
apply finish time day(2) to second(3) interval 10/29/2014 10:48:15
estimated startup time 20 second 10/29/2014 10:48:15
4. 由于主备库都是rac ,此环境下主库和备库都只有一个实例存活
srvctl stop instance -d EM -i EM2 --先停止主库
srvctl stop instance -d EM_SH -i EMP2 --停止备库
NOTE:如果主库两个实例都存活会报错如下:
SQL> alter database commit to switchover to physical standby with session shutdown;
alter database commit to switchover to physical standby with session shutdown
*
ERROR at line 1:
ORA-01105: mount is incompatible with mounts by other instances
5.登录主库操作
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE; -- 确保状态为SESSION_ACTIVE 或者TO STANDBY(由于是异地可能在shut一个实例后,redo应用会有延迟,如果网络质量不太好,可等一等 )
alter database commit to switchover to physical standby with session shutdown; --执行切换(最好把应用停掉 ) --执行完此操作后,数据库会自动shut
STARTUP MOUNT; -- 启动原来主库到mount
6.登录备库操作
SELECT SWITCHOVER_STATUS FROM V$DATABASE; -- 确保状态会SESSION_ACTIVE或者TO PRIMARY.
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN; --执行角色切换
ALTER DATABASE OPEN;--打开新主库
srvctl start instance -d databasename -i instance_name --启动另外的节点
7.登录新的备库
ALTER DATABASE OPEN; --启动库
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT; - -启动实时应用
srvctl start instance -d databasename -i instance_name; --启动其他实例
8.进行事务,发现并没有同步过来
archive log list 发现scn都没有
经过核查是因为主库并没有日志传输
alter system set log_archive_dest_state_2='enable' sid='*'; --在新的主库执行,启动日志传输服务
有可能查询数据的状态为:
SWITCHOVER_STATUS
--------------------
FAILED DESTINATION
查看备库的scn没有变化,可重启下备库。
9.检查是否同步
SELECT MAX(SEQUENCE#),THREAD# FROM V$ARCHIVED_LOG
WHERE RESETLOGS_CHANGE# = (SELECT MAX(RESETLOGS_CHANGE#) FROM V$ARCHIVED_LOG) GROUP BY THREAD#;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2637881/,如需转载,请注明出处,否则将追究法律责任。