單節點DG的switchover切換介紹

龍山游龍發表於2015-07-11
本章主要介紹DG的switchover切換,當用方法論來統籌知識和經驗的時候,操作筆記的價值並不大,不過新手可以借鑑
PRIMARY:
主庫是處於open狀態,有業務訪問,v$database檢視中的switchover_status欄位為sessions active
由primary切換到standby需要資料庫為open狀態,若v$database檢視中的switchover_status欄位為sessions active,執行切換命令時,帶上with session shutdown選項即可

SQL> select database_role,switchover_status from v$database;
SQL> alter database commit to switchover to physical standby with session shutdown;
SQL> shutdown abort;
SQL> startup mount;
SQL> alter database recover managed standby database disconnect from session/using current logfile disconnect from session;
SQL> select database_role,switchover_status from v$database;

PHYSICAL STANDBY:
確認是否可以切換為主庫,如果switchover_status為recovery needed或switchover latent,需要apply完所有歸檔日誌才能切換
如果是sessions active則帶上with session shutdown選項。apply完所有日誌後,即可切換為primary,然後開啟資料庫
檢視alert.log可以看到備庫做了哪些動作:接收主庫日誌,接收到主庫End-Of-REDO的訊號,apply完所有日誌,清空online redo log以便開啟資料庫,切換為primary,開啟資料庫

SQL> select database_role,switchover_status from v$database;
SQL> alter database recover managed standby database disconnect from session; #結束備庫歸檔apply
SQL> alter database commit to switchover to primary with session shutdown;
SQL> alter database open;
SQL> select database_role,switchover_status from v$database;
------------------------------------------------------------------------------------------------------------------------------------------
以上過過程中,由於主庫斷開所有session並歸檔,傳輸日誌到備庫,發給備庫End-Of-REDO的訊號,因此正常switchover時,是不會丟失資料的。
切換完成後可以在主庫歸檔,驗證一下是否切換成功,備庫是否能正常接收日誌。
------------------------------------------------------------------------------------------------------------------------------------------
switchover 主備切換演練,操作筆記

PRIMARY:
SQL> show user
USER is "SYS"
SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL>

PHYSICAL STANDBY:
SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL> select sequence#,applied from v$archived_log;

 SEQUENCE# APPLIED
---------- ---------
        40 YES
        41 YES
        42 YES
        44 YES
        45 YES
        43 YES
        46 YES
        47 YES
        48 YES
        49 IN-MEMORY

SQL> alter database recover managed standby database cancel;

Database altered.
此時,DG執行正常,接下來進行switchover切換
-------------------------------------------------------------------------------

PRIMARY:
SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PRIMARY          TO STANDBY

SQL> alter database commit to switchover to physical standby;

Database altered.
注:若這邊發現switchover_status狀態為sessions active,則切換到physical standby時需要加上with session shutdown
執行完切換命令後,關閉資料庫,重新啟動資料庫到mount狀態,接受日誌傳輸,開啟日誌應用
SQL> shutdown immediate
SQL> startup mount;
ORACLE instance started.

Total System Global Area  409194496 bytes
Fixed Size                  2228864 bytes
Variable Size             339742080 bytes
Database Buffers           62914560 bytes
Redo Buffers                4308992 bytes
Database mounted.
SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY RECOVERY NEEDED

SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY NOT ALLOWED

SQL>
-------------------------------------------------------------------------------

PHYSICAL STANDBY:

當主庫已經將database_role從PRIMARY切換至PHYSICAL STANDBY,此時檢視備庫的database_role和switchover_status
SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL>  select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY

SQL> alter database commit to switchover to primary;

Database altered.

SQL> alter database open;

Database altered.

SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PRIMARY          TO STANDBY

-------------------------------------------------------------------------------
驗證筆記
原備庫:
SQL> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
beiku            OPEN

SQL>
SQL>
SQL>
SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /
 
System altered.

SQL> /

System altered.

SQL> /

System altered.

原主庫
SQL> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
zhuku            MOUNTED

SQL> select sequence#,applied from v$archived_log;

 SEQUENCE# APPLIED
        57 YES
        56 YES
        58 YES
        59 YES
        60 YES
        61 YES
        62 YES
        63 YES
DG已經執行正常
至此,單節點DG的switchover切換已經完成,failover切換可能在後續的章節中介紹

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

相關文章