DATA GUARD物理STANDBY的FAILOVER切換

season0891發表於2011-11-07

物理STANDBYFAILOVER切換會把當前的一個物理STANDBY切換為PRIMARY資料庫。


FAILOVER切換一般是PRIMARY資料庫發生故障後的切換,這種情況是STANDBY資料庫發揮其作用的情況。這種切換髮生後,可能會造成資料的丟失。而且這個過程不是可逆的,DATA GUARD環境會被破壞。

由於PRIMARY資料庫已經無法啟動,所以FAILOVER切換所需的條件並不多,只要檢查STANDBY是否執行在最大保護模式下,如果是的話,需要將其置為最大效能模式,否則切換到PRIMARY角色也無法啟動。

為了模擬FAILOVER的特點,首先在主庫上執行一個比較大的事務,然後透過SHUTDOWN ABORT來關閉PRIMARY資料庫:

[oracle@yangtk ~]$ sqlplus yangtk/yangtk

SQL*Plus: Release 11.1.0.6.0 - Production on Mon Nov 5 13:11:14 2007

Copyright (c) 1982, 2007, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> CREATE TABLE T_FAILOVER (ID NUMBER);

Table created.

SQL> DECLARE
2 V_JOB NUMBER;
3 BEGIN
4 DBMS_JOB.SUBMIT(V_JOB,
5 'BEGIN FOR I IN 1..10000000 LOOP INSERT INTO T_FAILOVER VALUES (I); COMMIT; END LOOP; END;',
6 SYSDATE);
7 COMMIT;
8 END;
9 /

PL/SQL procedure successfully completed.

SQL> ALTER SYSTEM SWITCH LOGFILE;

System altered.

SQL> CONN / AS SYSDBA
Connected.
SQL> ALTER SYSTEM SWITCH LOGFILE;

System altered.

SQL> SHUTDOWN ABORT
ORACLE instance shut down.

下面登陸STANDBY資料庫:

[oracle@yangtk2 ~]$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.1.0.6.0 - Production on Mon Nov 26 19:57:11 2007

Copyright (c) 1982, 2007, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

no rows selected

檢查是否存在GAP,如果存在複製相應的歸檔到STANDBY資料庫,並註冊,再次執行上面的查詢,直到上面的查詢不返回記錄。

PRIMARY資料庫和其他的資料庫中檢查是否存在本地沒有的歸檔檔案,複製並註冊這些檔案:

SQL> SELECT UNIQUE THREAD#, MAX(SEQUENCE#) OVER(PARTITION BY THREAD#) LAST FROM V$ARCHIVED_LOG;

THREAD# LAST
---------- ----------
1 228

把所有的歸檔都複製到STANDBY站點,使用ALTER DATABASE REGISTER PHYSICAL LOGFILE語句進行註冊,然後停止應用歸檔:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

Database altered.

下面將STANDBY資料庫切換為PRIMARY資料庫:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

Database altered.

SQL> SELECT DATABASE_ROLE FROM V$DATABASE;

DATABASE_ROLE
----------------
PHYSICAL STANDBY

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

Database altered.

SQL> ALTER DATABASE OPEN;

Database altered.

檢查資料庫是否已經切換成功:

SQL> SELECT DATABASE_ROLE FROM V$DATABASE;

DATABASE_ROLE
----------------
PRIMARY

至此,FAILOVER切換完成。這個時候應該馬上對新的PRIMARY資料庫進行備份。

歸檔是否都複製到本地,和志傳輸的方式,決定FAILOVER過程是否會丟失資料。這個例子中FAILOVER切換沒有造成資料的丟失:

SQL> SELECT COUNT(*) FROM YANGTK.T_FAILOVER;

COUNT(*)
----------
77880

重啟原來的PRIMARY資料庫:

SQL> STARTUP
ORACLE instance started.

Total System Global Area 267825152 bytes
Fixed Size 1299316 bytes
Variable Size 167775372 bytes
Database Buffers 96468992 bytes
Redo Buffers 2281472 bytes
Database mounted.
Database opened.
SQL> SELECT COUNT(*) FROM YANGTK.T_FAILOVER;

COUNT(*)
----------
77880


come from :http://space.itpub.net/?uid-4227-action-viewspace-itemid-69525

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

相關文章