​Oracle 11g dg broker自動failover

賀子_DBA時代發表於2019-07-04
Oracle 11g dg broker自動failover驗證:
db2主庫:
SQL> select  DATABASE_ROLE,OPEN_MODE from  v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PRIMARY          READ WRITE
db1為standby
SQL> select  DATABASE_ROLE,OPEN_MODE from  v$database;
DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY
db2主庫模擬異常關閉
SQL> shu abort
ORACLE instance shut down.
再次檢視db1的狀態:
SQL> select  DATABASE_ROLE,OPEN_MODE from  v$database;
DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PRIMARY          READ WRITE
四:自動切換的過程:
4.1:測試大概需要10秒observer去探測到主庫發生故障!
DGMGRL> start  observer;
Observer started
20:15:59.44  Thursday, July 04, 2019
Initiating Fast-Start Failover to database "db2"...
Performing failover NOW, please wait...
Failover succeeded, new primary is "db2"
20:16:01.77  Thursday, July 04, 2019
4.2 failover的過程和手工failover一樣,不管是自動failver,還是手動執行FAILOVER TO ,都是執行了用命令列failover的命令如下兩條命令:
alter database  recover managed standby database finish force;---停止rfs程式
alter database commit to switchover to primary;---由open到mount
alter database open;      ----read write 方式開啟
發生failover的時候,透過如下可以看到確實是這麼個過程
1).開始狀態: rfs和mrp程式都正常
SQL> select  process,status ,sequence# from v$managed_standby;

PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CLOSING              14
RFS       IDLE                  0
RFS       IDLE                 15
RFS       IDLE                  0
MRP0      APPLYING_LOG         15

8 rows selected.
2).rsf程式消失
SQL> select  process,status ,sequence# from v$managed_standby;

PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CLOSING              14
MRP0      APPLYING_LOG         15
3).資料庫變成了mounted
SQL> select  DATABASE_ROLE,OPEN_MODE from  v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED
4)資料庫變成open  write了
SQL> select  DATABASE_ROLE,OPEN_MODE from  v$database;
DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PRIMARY          READ WRITE
4.3:手動執行failover;
DGMGRL> help failover
Changes a standby database to be the primary database
Syntax:
FAILOVER TO <standby database name> [IMMEDIATE];
當發生failover的之後:
檢視 configuration的狀態:發現原來的主庫 needs to be reinstated,需要使用REINSTATE命令修復下,才能變成新的主庫的從庫!
DGMGRL> show configuration
Configuration - dbha_c
Protection Mode: MaxPerformance
Databases:
db2 - Primary database
Warning: ORA-16829: fast-start failover configuration is lagging
db1 - (*) Physical standby database (disabled)
ORA-16661: the standby database needs to be reinstated
Fast-Start Failover: ENABLED
Configuration Status:
WARNING
首先啟動原來的主庫到mount狀態:
SQL> startup mount
DGMGRL> help  reinstate
Changes a database marked for reinstatement into a viable standby
Syntax:
REINSTATE DATABASE <database name>;

DGMGRL> REINSTATE DATABASE  db1
Reinstating database "db1", please wait...
Reinstatement of database "db1" succeeded
再次檢視原來的主庫:
SQL> select  process,status ,sequence# from v$managed_standby;

PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CLOSING               5
RFS       IDLE                  0
RFS       IDLE                  0
RFS       IDLE                  0
RFS       IDLE                  6
MRP0      APPLYING_LOG          6

實際上reinstate就是執行了下面的過程:
如果要轉換原來的主庫為新的備庫
要求原先的主庫必須開啟了flashbackup database的功能,在failover後,
1.檢視從庫failover成為主的時候的scn號。
SQL> select  STANDBY_BECAME_PRIMARY_SCN      from  v$database;

STANDBY_BECAME_PRIMARY_SCN
--------------------------
15468
2.閃回原來的主庫到15468 的scn號;
SQL>FLASHBACK DATABASE TO SCN 15468 ;
Database altered.
3.在原來主庫執行切換:
SQL> alter database convert to physical standby  ;
Database altered.
4.關閉原來的主庫
SQL>shu  immediate
5.開啟原來的主庫到mount狀態,
SQL>startup mount;
6.在新的主庫上把新產生的日誌歸檔到新的備庫
SQL>alter system archive log  current;
7.開啟mrp程式應用日誌,重演變化
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
5.檢視狀態:
SQL> select process,status from v$managed_standby;

PROCESS   STATUS
--------- ------------
ARCH   CLOSING
ARCH   CONNECTED
ARCH   CONNECTED
ARCH   CLOSING
MRP0   APPLYING_LOG
RFS   IDLE
RFS   IDLE
RFS   IDLE
至此將原來的主庫成為了新的主的standby了。。。。。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29654823/viewspace-2649606/,如需轉載,請註明出處,否則將追究法律責任。

相關文章