【前言】Dataguard的从库一般情况下都是出于数据的抽取和查询的作用的,但是万一在主库发生故障的情况下就需要切换到备库了。而这种故障的切换往往又是灾难性的情况:比如主库的服务器根本就起不来了,没有办法进行正常的切换,就需要强制的把从库切换成主库了。
【操作步骤】这个时候主库根本是操作不了的,所以只需在从库执行以下操作
【1】停止应用恢复模式
alter database recover managed standby database finish;
【2】从库切换成主库
alter database commit to switchover to primary;
【3】启动数据库
Alter database open;
【4】检查备库的状态
select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE-------------- ---------------------- OPEN PRIMARY
【其他】切换完成后,就需要更改应用的连接IP地址和相关的一系列的连接(DBLINK等其他接口),如果再规划的时候就把这部分的内容考虑过去的话,那么就减少了很多切换后的工作。
如果服务器的IP地址不变的话,那么就可以节省很多的工作了。这就需要前期的规划:通过负载均衡设置一个虚拟ip,当服务器发生故障后,切换虚拟ip对应的实体ip就好了。如果没有这个硬件的话,通过软件也是可以实现的比如:keepalived工具等。
附:切换日志
-
alter database recover managed standby database finish 停止应用进行日志的恢复
-
Attempt to do a Terminal Recovery (DE2)
-
Media Recovery Start: Managed Standby Recovery (DE2)
-
started logmerger process
-
Wed Mar 29 10:21:35 2017
-
Managed Standby Recovery not using Real Time Apply
-
Parallel Media Recovery started with 8 slaves
-
Media Recovery Log /oracle/DE2/oraarch/DE2arch/1_565_912333510.dbf
-
Media Recovery Waiting for thread 1 sequence 566 (in transit)
-
krsv_proc_kill: Killing 4 processes (all RFS, wait for I/O)
-
Begin: Standby Redo Logfile archival
-
End: Standby Redo Logfile archival
-
Terminal Recovery timestamp is '03/29/2017 10:21:43'
-
Terminal Recovery: applying standby redo logs.
-
Terminal Recovery: thread 1 seq# 566 redo required
-
Terminal Recovery:
-
Recovery of Online Redo Log: Thread 1 Group 14 Seq 566 Reading mem 0
-
Mem# 0: /oracle/DE2/mirrlogA/sredo14.log
-
Identified End-Of-Redo (failover) for thread 1 sequence 566 at SCN 0xffff.ffffffff
-
Wed Mar 29 10:21:48 2017
-
Incomplete Recovery applied until change 21240383491 time 03/29/2017 10:27:41
-
Wed Mar 29 10:21:48 2017
-
Media Recovery Complete (DE2)
-
Terminal Recovery: successful completion
-
Forcing ARSCN to IRSCN for TR 4:4060514307
-
Attempt to set limbo arscn 4:4060514307 irscn 4:4060514307
-
Resetting standby activation ID 1489765315 (0x58cc03c3)
-
Wed Mar 29 10:21:51 2017
-
ARCH: Archival stopped, error occurred. Will continue retrying
-
ORACLE Instance DE2 - Archival Error
-
ORA-16014: log 14 sequence# 566 not archived, no available destinations
-
ORA-00312: online log 14 thread 1: '/oracle/DE2/mirrlogA/sredo14.log'
-
Completed: alter database recover managed standby database finish 完成日志的应用
-
Wed Mar 29 10:22:12 2017
-
alter database commit to switchover to primary 从库切换成主库
-
ALTER DATABASE SWITCHOVER TO PRIMARY (DE2)
-
Maximum wait for role transition is 15 minutes.
-
CLOSE: killing server sessions.
-
CLOSE: all sessions shutdown successfully.
-
Wed Mar 29 10:22:12 2017
-
SMON: disabling cache recovery
-
Backup controlfile written to trace file /oracle/DE2/saptrace/diag/rdbms/de2dg/DE2/trace/DE2_ora_9961494.trc
-
Standby terminal recovery start SCN: 21240295534
-
RESETLOGS after incomplete recovery UNTIL CHANGE 21240383491 重建redolog
-
Online log /oracle/DE2/mirrlogB/log_g15m1.dbf: Thread 1 Group 5 was previously cleared
-
Online log /oracle/DE2/mirrlogB/log_g15m2.dbf: Thread 1 Group 5 was previously cleared
-
Online log /oracle/DE2/mirrlogA/log_g16m1.dbf: Thread 1 Group 6 was previously cleared
-
Online log /oracle/DE2/mirrlogA/log_g16m2.dbf: Thread 1 Group 6 was previously cleared
-
Online log /oracle/DE2/mirrlogB/log_g17m2.dbf: Thread 1 Group 7 was previously cleared
-
Online log /oracle/DE2/mirrlogB/log_g17m1.dbf: Thread 1 Group 7 was previously cleared
-
Online log /oracle/DE2/mirrlogA/log_g18m2.dbf: Thread 1 Group 8 was previously cleared
-
Online log /oracle/DE2/mirrlogA/log_g18m1.dbf: Thread 1 Group 8 was previously cleared
-
Standby became primary SCN: 21240295533
-
Wed Mar 29 10:22:13 2017
-
Setting recovery target incarnation to 3
-
Switchover: Complete - Database mounted as primary
-
Completed: alter database commit to switchover to primary 完成切换
-
Wed Mar 29 10:22:37 2017
-
alter database open
-
Data Guard Broker initializing...
-
Data Guard Broker initialization complete
-
Data Guard: verifying database primary role...