【DG】DG的3種保護模式

lhrbest發表於2017-06-24

【DG】DG的3種保護模式




DG提供了3種資料保護模式最大保護(Maximum Protection)、最高效能(Maximum Performance)和最高可用(Maximum Availability),如下表所示:

3-32 DG三種模式的區別





資料庫異地備份方案


在對資料庫計劃實施異地備份時,需要理解異地備份的目的。一般情況下有兩種異地備份的需求:一是確保業務的實時以及最大程度減少由於單點故障導致業務中斷;二是確保資料的安全,當生產節點出現物理故障時能透過異地備份及時的恢復資料。



【DG】DG的3種保護模式 非實時異地備份【DG】DG的3種保護模式

     如果只需實現資料的安全,而毋須關注業務的恢復時間以及資料的丟失情況。 那麼可以透過非實時的異地備份而簡易實現。

    非實時的異地備份可以透過磁碟或者磁帶介質來實現。

    採用磁帶來實現資料的安全性是傳統的異地備份方式,採用此種方式,主要受限於磁帶的讀寫速度偏慢,當需要執行恢復時,如果資料量很大,恢復的時間那是相當漫長。另外,需要使用第三方備份軟體實現資料與磁帶之間的互動;

   採用磁碟來實現資料庫的安全性備份是近年來相對流行的異地備份方式,主要由於目前磁碟價格便宜,並且讀寫速度相對較高,因而比較受使用者的青睞。經常的做法是透過異地的儲存或者主機做為備份節點,當生產節點的資料備份出來之後,透過網路傳輸至備份節點,確保備份的安全;採用此種方式備份,對網路穩定要求較高。如果在執行資料傳輸出現網路故障,那麼傳輸將會中斷。另外,如果採用異地主機作為備份節點,建議備份節點的作業系統型別、晶片架構與生產節點的一致。


【DG】DG的3種保護模式 實時異地備份【DG】DG的3種保護模式

近年來,由於業務的發展以及技術的飛越。很多實時的異地備份方案出現,極大程度確保了資料的安全以及業務的穩定性。針對 Oracle 資料庫,目前主流使用 Oracle DataGuard、Oracle Goldengate 作為災備技術實現資料庫的實時異地備份。當然還有 Vertias 的相關儲存映象管理軟體來實現。

    以下著重瞭解 Oracle DataGuard 的實現方式。


Oracle DataGuard 結構

【DG】DG的3種保護模式

 如上圖所述,結構中的備用資料庫分成物理備用資料庫和邏輯備用資料庫。


【DG】DG的3種保護模式

在物理備用資料庫中,將重做日誌使用資料庫恢復功能來應用。


【DG】DG的3種保護模式

   在邏輯備用資料庫中,將重做日誌轉換成 SQL,使用這些 SQL 在邏輯備用資料庫上 自動操作。


DataGuard 的保護模式

   在 Data Guard 模式下,資料庫的保護模式分成下列三種:

【DG】DG的3種保護模式

最大保護模式

1)這種模式提供了最高階別的資料保護能力;

2)要求至少一個物理備庫收到重做日誌後,主庫的事務才能夠提交;

3)主庫找不到合適的備庫寫入時,主庫會自動關閉,防止未受保護的資料出現;

 4)優點:該模式可以保證備庫沒有資料丟失;

5)缺點:備庫的自動關閉會影響到主庫的可用性,同時需要備庫恢復後才能提交,對網路等客觀條件要求非常的高,主庫的效能會因此受到非常大的衝擊。


最大可用性模式

1)該模式提供了僅次於“最大保護模式”的資料保護能力;

2)要求至少一個物理備庫收到重做日誌後,主庫的事務才能夠提交;

3)主庫找不到合適的備庫寫入時,主庫不會關閉,而是臨時降低到“最大效能模式”模式,直到問題得到處理;

4)優點:該模式可以在沒有問題出現的情況下,保證備庫沒有資料丟失,是一種折中的方法;

5)缺點:在正常執行的過程中缺點是主庫的效能受到諸多因素的影響。


最大效能模式

1)該模式是預設模式,可以保證主資料庫的最高可用性;

2)保證主庫執行過程中不受備庫的影響,主庫事務正常提交,不因備庫的任何問題影響到主庫的執行;

4)優點:避免了備庫對主資料庫的效能和可用性影響;

5)缺點:如果與主庫提交的事務相關的恢復資料沒有傳送到備庫,這些事務資料將被丟失,不能保證資料無損失;


   採用 Oracle DataGuard,最大的受限在於主備資料庫主機需要採用同晶片架構的主機。鑑於此,不能跨作業系統平臺實現 Oracle DataGuard 的應用。另外,Oracle DataGuard 是 Oracle 企業版資料庫的一種特性,毋須其它 license。






Data GuardOracle高可用性HA的重要解決方案。針對不同的系統保護需求,DG提供了三種不同型別的保護模式(Protection Mode),分別為:最大保護(Maximum Protection)、最大可用(Maximum Availability)和最大效能(Maximum performance)。在實際應用場景下,我們需要根據不同的業務場景和資料可用性需求,來設定DG環境的保護型別。


1、三種保護模式Protection Mode


三種保護模式是DG的核心概念。DG本質上是一種基於Redo Log的資料同步機制。UndoRedoOracle早期奠定行業地位的核心技術。Undo負責記錄事務操作的前映象,而Redo負責記錄事務操作的後映象。在Oracle事務commit的動作中,寫入日誌檔案是一個一定需要完成的動作。寫入日誌檔案之後,即使立刻出現嚴重的例項終止事件,在重新啟動例項的時候也會進行例項恢復動作,將事務落實。


DG環境中,無論採用何種初始化方法,都是確保一個PrimaryStandby的初始化資料一致,之後Primary一端接收的事務型別操作,均會以歸檔日誌串列的方式傳遞到Standby端的standby redo log和歸檔日誌列表中,最後重複應用這些日誌,實現PrimaryStandby端一致。


PrimaryStandby是相互為備份的冗餘結構,Standby跟隨Primary的情況,反映了HA結構的可用性級別。理論上,最保險的策略是一個事務要保證在PrimaryStandby上都提交了,才返回給使用者說已經完成。這樣是可以保證主備庫完全一致的最保險做法。另一個極端情況,就是主庫“自顧自”進行事務處理,獨立將日誌進行傳輸,也不用管日誌是否傳輸到或者應用到。


針對不同的傳輸情況,DG區分為三種保護型別:


ü  最大可用模式Maximum Availability


在官方文件中,對這種模式的描述如下:


This protection mode provides the highest level of data protection that is possible without compromising the availability of a primary database. Transactions do not commit until all redo data needed to recover those transactions has been written to the online redo log and to the standby redo log on at least one synchronized standby database. If the primary database cannot write its redo stream to at least one synchronized standby database, it operates as if it were in maximum performance mode to preserve primary database availability until it is again able to write its redo stream to a synchronized standby database.


Maximum Availability模式下,事務只有在所有相關日誌都被傳輸到至少一個Standby端日誌的時候,才可以正式提交。但是,如果Primary在傳輸日誌的過程中,發現所有standby端都不能進行傳輸,模式會退化到最大效能模式(Maximum Performance)工作方式。應該說,Maximum Availability是一種自適應的保護模式,當出現問題的時候,DG會退而求其次,確保Primary主庫事務進行。


ü  最大效能模式(Maximum Performance


官方文件中介紹如下:“This protection mode provides the highest level of data protection that is possible without affecting the performance of a primary database. This is accomplished by allowing transactions to commit as soon as all redo data generated by those transactions has been written to the online log. Redo data is also written to one or more standby databases, but this is done asynchronously with respect to transaction commitment, so primary database performance is unaffected by delays in writing redo data to the standby database(s).

This protection mode offers slightly less data protection than maximum availability mode and has minimal impact on primary database performance.

This is the default protection mode.


最大效能模式是在不影響主庫工作情況下,可以提供的最高資料保護級別。當事務進行提交的時候,主庫不會去確認日誌是否寫入到備庫中,更不會確認是否被apply。這種方式下,主庫的工作效能是不會收到備庫提交應用的影響的。當然,這種保護模式會有一定的事務資料丟失,但是絕對不會出現資料誤提交的情況。


DG而言,最大效能模式是預設的保護模式。當我們完成了DG安裝之後,就自動進入了Maximum Performance模式。


ü  最大保護模式(Maximum Protection


最大保護模式在官方中的描述為:


This protection mode ensures that no data loss will occur if the primary database fails. To provide this level of protection, the redo data needed to recover a transaction must be written to both the online redo log and to the standby redo log on at least one synchronized standby database before the transaction commits. To ensure that data loss cannot occur, the primary database will shut down, rather than continue processing transactions, if it cannot write its redo stream to at least one synchronized standby database.

Transactions on the primary are considered protected as soon as Data Guard has written the redo data to persistent storage in a standby redo log file. Once that is done, acknowledgment is quickly made back to the primary database so that it can proceed to the next transaction. This minimizes the impact of synchronous transport on primary database throughput and response time. To fully benefit from complete Data Guard validation at the standby database, be sure to operate in real-time apply mode so that redo changes are applied to the standby database as fast as they are received. Data Guard signals any corruptions that are detected so that immediate corrective action can be taken.


最大保護模式是完全HA架構理想中的事務模式。如果Primary資料庫進行一個事務,連帶Standby資料庫也要同步進行操作。如果由於網路、執行模式等原因,Standby不能夠跟上主庫的操作,那麼主庫會放棄事務,並且強制停庫。


保護模式的三種和資料庫之間傳輸日誌的機制是密切相關的。主要體現是否同步傳輸Redo日誌和對日誌進行確認兩個方面。我們配置三種日誌模式,一定要以Log_Archive_Config引數配置為基礎。


Maximum Availability

Maximum Performance

Maximum Protection

AFFIRM

NOAFFIRM

AFFIRM

SYNC

ASYNC

SYNC

DB_UNIQUE_NAME

DB_UNIQUE_NAME

DB_UNIQUE_NAME


下面透過一系列的測試,來分析三種保護模式的工作行為方式。


2、環境介紹


筆者使用環境為Oracle 11gR2,具體版本為11.2.0.4。主備庫環境已經搭建完成,同步保護模式是採用預設方式。


主庫資訊:



SQL> select name, open_mode, database_role, protection_mode from v$database;

NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ WRITE           PRIMARY          MAXIMUM PERFORMANCE


SQL> select instance_name from v$instance;

INSTANCE_NAME

----------------

vlife



主庫與備庫連線方式,採用預設的非同步非確認方式。



SQL> select dest_id, dest_name, TRANSMIT_MODE, ASYNC_BLOCKS, AFFIRM TYPE, VALID_NOW, VALID_TYPE, VALID_ROLE, DB_UNIQUE_NAME from v$archive_dest where status<>'INACTIVE';


   DEST_ID DEST_NAME            TRANSMIT_MODE ASYNC_BLOCKS TYPE VALID_NOW        VALID_TYPE      VALID_ROLE   DB_UNIQUE_NAME

---------- -------------------- ------------- ------------ ---- ---------------- --------------- ------------ ---------------

         1 LOG_ARCHIVE_DEST_1   SYNCHRONOUS              0 NO   YES              ALL_LOGFILES    ALL_ROLES    NONE

         2 LOG_ARCHIVE_DEST_2   ASYNCHRONOUS         61440 NO   YES              ONLINE_LOGFILE  PRIMARY_ROLE vlifesb



此時,傳輸通道配置。



SQL> show parameter LOG_ARCHIVE_DEST_2;


NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

log_archive_dest_2                   string      SERVICE=vlifesb valid_for=(online_logfiles,primary_role) db_unique_name=vlifesb

log_archive_dest_20                  string     

log_archive_dest_21                  string     



備庫資訊如下:



SQL> select name, open_mode, database_role, protection_mode from v$database;


NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PERFORMANCE


SQL> select instance_name from v$instance;


INSTANCE_NAME

----------------

vlifesb


SQL> col dest_name for a20;

SQL> select dest_id, dest_name, TRANSMIT_MODE, ASYNC_BLOCKS, AFFIRM TYPE, VALID_NOW, VALID_TYPE, VALID_ROLE, DB_UNIQUE_NAME from v$archive_dest where status<>'INACTIVE';


   DEST_ID DEST_NAME            TRANSMIT_MODE ASYNC_BLOCKS TYPE VALID_NOW        VALID_TYPE      VALID_ROLE   DB_UNIQUE_NAME

---------- -------------------- ------------- ------------ ---- ---------------- --------------- ------------ ------------------------------

         1 LOG_ARCHIVE_DEST_1   SYNCHRONOUS              0 NO   YES              ALL_LOGFILES    ALL_ROLES    NONE

         2 LOG_ARCHIVE_DEST_2   ASYNCHRONOUS         61440 NO   WRONG VALID_TYPE ONLINE_LOGFILE  PRIMARY_ROLE vlife

        32 STANDBY_ARCHIVE_DEST SYNCHRONOUS              0 NO   YES              ALL_LOGFILES    ALL_ROLES    NONE



SQL> show parameter LOG_ARCHIVE_DEST_2;


NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

log_archive_dest_2                   string      SERVICE=vlife valid_for=(online_logfiles,primary_role) db_unique_name=vlife

log_archive_dest_20                  string     

log_archive_dest_21                  string     



3、最大可用模式Maximum Availability Mode測試


當前從預設的最大效能切換到最大可用模式,首先需要滿足將日誌傳輸模式進行修改。



SQL> alter system set log_archive_dest_2='SERVICE=vlifesb sync affirm net_timeout=30 valid_for=(online_logfiles,primary_role) db_unique_name=vlifesb';


System altered


SQL> select dest_id, dest_name, TRANSMIT_MODE, ASYNC_BLOCKS, AFFIRM TYPE, VALID_NOW, VALID_TYPE, VALID_ROLE, DB_UNIQUE_NAME, NET_TIMEOUT from v$archive_dest where status<>'INACTIVE';


   DEST_ID DEST_NAME            TRANSMIT_MODE ASYNC_BLOCKS TYPE VALID_NOW        VALID_TYPE      VALID_ROLE   DB_UNIQUE_NAME                 NET_TIMEOUT

---------- -------------------- ------------- ------------ ---- ---------------- --------------- ------------ ------------------------------ -----------

         1 LOG_ARCHIVE_DEST_1   SYNCHRONOUS              0 NO   YES              ALL_LOGFILES    ALL_ROLES   NONE                                     0

         2 LOG_ARCHIVE_DEST_2   PARALLELSYNC             0 YES  YES              ONLINE_LOGFILE  PRIMARY_ROLE vlifesb                                 30



此時,將保護模式使用alter database進行設定。



SQL> alter database set standby database to maximize availability;

Database altered


SQL> select name, open_mode, database_role, protection_mode from v$database;


NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ WRITE           PRIMARY          MAXIMUM AVAILABILITY



在切換動作的時候,主庫日誌情況如下:



Wed Oct 21 15:13:48 2015

alter database set standby database to maximize availability


Completed: alter database set standby database to maximize availability


Wed Oct 21 15:13:49 2015

Destination LOG_ARCHIVE_DEST_2 is UNSYNCHRONIZED –發現沒有同步,需要補充。

******************************************************************

LGWR: Setting 'active' archival for destination LOG_ARCHIVE_DEST_2

******************************************************************

Wed Oct 21 15:13:49 2015

NSS2 started with pid=34, OS id=9186

LGWR: Standby redo logfile selected to archive thread 1 sequence 82

LGWR: Standby redo logfile selected for thread 1 sequence 82 for destination LOG_ARCHIVE_DEST_2

Thread 1 advanced to log sequence 82 (LGWR switch)

  Current log# 3 seq# 82 mem# 0: /u01/app/oracle/oradata/VLIFE/onlinelog/o1_mf_3_c1kb1c24_.log

  Current log# 3 seq# 82 mem# 1: /u01/app/oracle/fast_recovery_area/VLIFE/onlinelog/o1_mf_3_c1kb1c43_.log

Wed Oct 21 15:13:53 2015

Archived Log entry 104 added for thread 1 sequence 81 ID 0xfad4f44b dest 1:

Wed Oct 21 15:13:54 2015

ARC3: Archive log rejected (thread 1 sequence 81) at host 'vlifesb'

FAL[server, ARC3]: FAL archive failed, see trace file.

ARCH: FAL archive failed. Archiver continuing

ORACLE Instance vlife - Archival Error. Archiver continuing.

Wed Oct 21 15:14:42 2015

Destination LOG_ARCHIVE_DEST_2 is SYNCHRONIZED

LGWR: Standby redo logfile selected to archive thread 1 sequence 83

LGWR: Standby redo logfile selected for thread 1 sequence 83 for destination LOG_ARCHIVE_DEST_2

Thread 1 advanced to log sequence 83 (LGWR switch)

  Current log# 1 seq# 83 mem# 0: /u01/app/oracle/oradata/VLIFE/onlinelog/o1_mf_1_c1kb19q4_.log

  Current log# 1 seq# 83 mem# 1: /u01/app/oracle/fast_recovery_area/VLIFE/onlinelog/o1_mf_1_c1kb19sb_.log

Wed Oct 21 15:14:42 2015

Archived Log entry 107 added for thread 1 sequence 82 ID 0xfad4f44b dest 1:



Primary端,在進行切換之後,Oracle發現傳輸狀態不是同步情況。於是自動加快進行日誌傳輸和同步動作。在Standby端,也可以看到後續追趕動作。



SQL> select name, open_mode, database_role, protection_mode from v$database;


NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM AVAILABILITY



Standby端上的日誌追趕動作。



Wed Oct 21 08:27:05 2015

Primary database is in MAXIMUM PERFORMANCE mode

Re-archiving standby log 4 thread 1 sequence 80

Wed Oct 21 08:27:05 2015

Media Recovery Waiting for thread 1 sequence 81

RFS[14]: Assigned to RFS process 31500

RFS[14]: Selected log 5 for thread 1 sequence 81 dbid -87496857 branch 892734889

Wed Oct 21 08:27:05 2015

Archived Log entry 76 added for thread 1 sequence 80 ID 0xfad4f44b dest 1:

Recovery of Online Redo Log: Thread 1 Group 5 Seq 81 Reading mem 0

  Mem# 0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_5_c265gqd8_.log

  Mem# 1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_5_c265gqj0_.log

Wed Oct 21 15:13:52 2015

Primary database is in MAXIMUM AVAILABILITY mode

Changing standby controlfile to MAXIMUM AVAILABILITY mode

Changing standby controlfile to RESYNCHRONIZATION level

Standby controlfile consistent with primary

RFS[15]: Assigned to RFS process 969

RFS[15]: Selected log 4 for thread 1 sequence 82 dbid -87496857 branch 892734889

Wed Oct 21 15:13:53 2015

Archived Log entry 77 added for thread 1 sequence 81 ID 0xfad4f44b dest 1:

Wed Oct 21 15:13:53 2015

Media Recovery Waiting for thread 1 sequence 82 (in transit)

Recovery of Online Redo Log: Thread 1 Group 4 Seq 82 Reading mem 0

  Mem# 0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log

  Mem# 1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log

Wed Oct 21 15:14:41 2015

Archived Log entry 78 added for thread 1 sequence 82 ID 0xfad4f44b dest 1:

Wed Oct 21 15:14:41 2015

Media Recovery Waiting for thread 1 sequence 83

Wed Oct 21 15:14:42 2015

Primary database is in MAXIMUM AVAILABILITY mode

Changing standby controlfile to MAXIMUM AVAILABILITY level

Standby controlfile consistent with primary

RFS[16]: Assigned to RFS process 976

RFS[16]: Selected log 4 for thread 1 sequence 83 dbid -87496857 branch 892734889

Recovery of Online Redo Log: Thread 1 Group 4 Seq 83 Reading mem 0

  Mem# 0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log

  Mem# 1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log



此時,兩個庫由於網路通暢,同步狀態正常,同步測試正常。



Maximium Availiablity模式下使用)

--主庫下

SQL> create table t_m as select * from dba_objects where rownum<10;

Table created


--Standby

SQL> select count(*) from t_m;


  COUNT(*)

----------

         9



如果此時中斷應用日誌,Standby情況如下:



SQL> alter database recover managed standby database cancel;

Database altered


SQL> select name, open_mode, database_role, protection_mode from v$database;


NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ ONLY            PHYSICAL STANDBY MAXIMUM AVAILABILITY



日誌情況如下:



Wed Oct 21 15:20:49 2015

alter database recover managed standby database cancel


Wed Oct 21 15:20:49 2015

MRP0: Background Media Recovery cancelled with status 16037

Errors in file /u01/app/oracle/diag/rdbms/vlifesb/vlifesb/trace/vlifesb_pr00_17539.trc:

ORA-16037: user requested cancel of managed recovery operation

Managed Standby Recovery not using Real Time Apply

Recovery interrupted!

Recovered data files to a consistent state at change 1692263

Wed Oct 21 15:20:49 2015

MRP0: Background Media Recovery process shutdown (vlifesb)

Managed Standby Recovery Canceled (vlifesb)

Completed: alter database recover managed standby database cancel



如果此時再中斷監聽器,中斷連線。此時資料庫不能做到實時同步。



[oracle@vLIFE-URE-OT-DB-STANDBY ~]$ lsnrctl stop


LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-OCT-2015 15:24:17

Copyright (c) 1991, 2013, Oracle.  All rights reserved.


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))

The command completed successfully


--主庫

***********************************************************************

Fatal NI connect error 12541, connecting to:

 (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.19.90)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=vlifesb)(CID=(PROGRAM=oracle)(HOST=vLIFE-URE-OT-DB-PRIMARY)(USER=oracle))))


  VERSION INFORMATION:

        TNS for Linux: Version 11.2.0.4.0 - Production

        TCP/IP NT Protocol Adapter for Linux: Version 11.2.0.4.0 - Production

  Time: 21-OCT-2015 15:24:38

  Tracing not turned on.

  Tns error struct:

    ns main err code: 12541

   

TNS-12541: TNS:no listener

    ns secondary err code: 12560

    nt main err code: 511

   

TNS-00511: No listener

    nt secondary err code: 111

    nt OS err code: 0

Error 12541 received logging on to the standby

Check whether the listener is up and running.

PING[ARC2]: Heartbeat failed to connect to standby 'vlifesb'. Error is 12541.



強制日誌切換。



SQL> alter system switch logfile;

System altered


SQL> alter system switch logfile;

System altered


SQL> alter system switch logfile;

System altered



SQL> select * from v$archive_dest_status;


   DEST_ID DEST_NAME            STATUS    TYPE           DATABASE_MODE   RECOVERY_MODE           PROTECTION_MODE     DESTINATION                                                                      STANDBY_LOGFILE_COUNT STANDBY_LOGFILE_ACTIVE ARCHIVED_THREAD# ARCHIVED_SEQ# APPLIED_THREAD# APPLIED_SEQ# ERROR                                                                            SRL DB_UNIQUE_NAME                 SYNCHRONIZATION_STATUS SYNCHRONIZED GAP_STATUS

---------- -------------------- --------- -------------- --------------- ----------------------- -------------------- -------------------------------------------------------------------------------- --------------------- ---------------------- ---------------- ------------- --------------- ------------ -------------------------------------------------------------------------------- --- ------------------------------ ---------------------- ------------ ------------------------

         1 LOG_ARCHIVE_DEST_1   VALID     LOCAL          OPEN            IDLE                    MAXIMUM PERFORMANCE /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch                                                     0                     0                1            85               0            0                                                                                 NO  NONE                           CHECK CONFIGURATION   NO          

         2 LOG_ARCHIVE_DEST_2   ERROR     PHYSICAL       OPEN_READ-ONLY  IDLE                    RESYNCHRONIZATION    vlifesb                                                                                             3                      0                1            82               1           82 ORA-12541: TNS: ???à?????ò                                                       YES vlifesb                        CHECK CONNECTIVITY    NO           RESOLVABLE GAP



SQL> select recid, name, sequence# from v$archived_log where sequence#>82;


     RECID NAME                                                                              SEQUENCE#

---------- -------------------------------------------------------------------------------- ----------

       108 vlifesb                                                                                  83

       109 /u01/app/oracle/fast_recovery_area/VLIFE/archivelog/2015_10_21/o1_mf_1_83_c2ghkz         83

       110 /u01/app/oracle/fast_recovery_area/VLIFE/archivelog/2015_10_21/o1_mf_1_84_c2ghl0         84

       111 /u01/app/oracle/fast_recovery_area/VLIFE/archivelog/2015_10_21/o1_mf_1_85_c2ghl4         85



standby端,歸檔日誌就沒有傳輸到。



SQL> select recid, name, sequence# from v$archived_log where sequence#>82;


     RECID NAME                                                                              SEQUENCE#

---------- -------------------------------------------------------------------------------- ----------

        79 /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_21/o1_mf_1_83_c2gh         83


SQL> select group#, dbid, archived from v$standby_log;


    GROUP# DBID                                     ARCHIVED

---------- ---------------------------------------- --------

         4 UNASSIGNED                               NO

         5 UNASSIGNED                               NO

         6 UNASSIGNED                               YES



此時,PrimaryStandby的連線明顯被中斷,日誌不能傳送,也就達不到同步確認的設定要求。但是此時,Primary還是可以進行事務操作。




(事務可以進行)

SQL> insert into t_m select * from dba_objects where rownum<10;

9 rows inserted


SQL> commit;

Commit complete



此時,如果恢復兩者連線,啟動監聽器和日誌應用。



[oracle@vLIFE-URE-OT-DB-STANDBY ~]$ lsnrctl start


LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-OCT-2015 15:51:46


Copyright (c) 1991, 2013, Oracle.  All rights reserved.


Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...


TNSLSNR for Linux: Version 11.2.0.4.0 - Production

System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

Log messages written to

(篇幅原因,有省略…….


SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered



之後主庫和從庫日誌上進行歸檔日誌傳輸和後續同步動作,篇幅原因,日誌資訊省略。


從上面實驗中,我們可以看到最大可用性模式的核心即使“可用”。所謂可用,即使保證PrimaryStandby整體的可用。如果在日誌傳輸通路順暢,兩者之間會維持嚴格的同步關係,行為類似於最大保護模式。但是,如果連線或者同步動作不能滿足要求,DG是不會終止例項執行,而是退而求其次,進行一種類似最大效能模式的工作方式。


4、最大保護模式Maximum Protection


最大保護模式是DG可以提供的最高保護級別,建立在日誌同步傳輸和確認的基礎上。同樣,可以使用alter database方法進行設定。



SQL> alter database set standby database to maximize protection;

Database altered



主庫上,可以檢視到狀態變化和日誌情況。



SQL> select name, open_mode, database_role, protection_mode from v$database;


NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ WRITE           PRIMARY          MAXIMUM PROTECTION


Wed Oct 21 16:17:46 2015

alter database set standby database to maximize protection

Completed: alter database set standby database to maximize protection


Wed Oct 21 16:17:50 2015

Destination LOG_ARCHIVE_DEST_2 is SYNCHRONIZED

******************************************************************

LGWR: Setting 'active' archival for destination LOG_ARCHIVE_DEST_2

******************************************************************

LGWR: Standby redo logfile selected to archive thread 1 sequence 89

LGWR: Standby redo logfile selected for thread 1 sequence 89 for destination LOG_ARCHIVE_DEST_2

Thread 1 advanced to log sequence 89 (LGWR switch)

  Current log# 1 seq# 89 mem# 0: /u01/app/oracle/oradata/VLIFE/onlinelog/o1_mf_1_c1kb19q4_.log

  Current log# 1 seq# 89 mem# 1: /u01/app/oracle/fast_recovery_area/VLIFE/onlinelog/o1_mf_1_c1kb19sb_.log

Wed Oct 21 16:17:50 2015

Archived Log entry 119 added for thread 1 sequence 88 ID 0xfad4f44b dest 1:



備庫上資訊也是同樣變化資訊。


SQL>  select name, open_mode, database_role, protection_mode from v$database;


NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PROTECTION



Wed Oct 21 15:52:45 2015

Primary database is in MAXIMUM AVAILABILITY mode

Changing standby controlfile to MAXIMUM AVAILABILITY level

Standby controlfile consistent with primary

RFS[21]: Assigned to RFS process 1172

RFS[21]: Selected log 4 for thread 1 sequence 88 dbid -87496857 branch 892734889

Recovery of Online Redo Log: Thread 1 Group 4 Seq 88 Reading mem 0

  Mem# 0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log

  Mem# 1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log

Wed Oct 21 16:17:49 2015

Archived Log entry 84 added for thread 1 sequence 88 ID 0xfad4f44b dest 1:

Wed Oct 21 16:17:49 2015

Media Recovery Waiting for thread 1 sequence 89

Wed Oct 21 16:17:50 2015

Primary database is in MAXIMUM PROTECTION mode

Changing standby controlfile to MAXIMUM PROTECTION mode

Standby controlfile consistent with primary

RFS[22]: Assigned to RFS process 1358

RFS[22]: Selected log 4 for thread 1 sequence 89 dbid -87496857 branch 892734889

Recovery of Online Redo Log: Thread 1 Group 4 Seq 89 Reading mem 0

  Mem# 0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log

  Mem# 1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log



如果此時,我們終止Standby端的同步動作。



SQL> alter database recover managed standby database cancel;

Database altered


SQL>  select name, open_mode, database_role, protection_mode from v$database;


NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ ONLY            PHYSICAL STANDBY MAXIMUM PROTECTION



此時,如果主庫有事務執行,是否可以執行成功呢?



主庫事務:

SQL> delete t_m;

9 rows deleted


SQL> commit;

Commit complete


備庫

SQL> select count(*) from t_m;

  COUNT(*)

----------

         9



事務操作並沒有能夠傳遞到備庫上。當前的日誌傳輸機制是正常的,如果我們切斷了這種連線,處在最大保護模式下的Primary端如何。



[oracle@vLIFE-URE-OT-DB-STANDBY ~]$ lsnrctl stop


LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-OCT-2015 16:25:30


Copyright (c) 1991, 2013, Oracle.  All rights reserved.


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))

The command completed successfully



主庫中立刻就有中斷資訊的顯示:


***********************************************************************


Fatal NI connect error 12541, connecting to:

 (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.19.90)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=vlifesb)(CID=(PROGRAM=oracle)(HOST=vLIFE-URE-OT-DB-PRIMARY)(USER=oracle))))


  VERSION INFORMATION:

        TNS for Linux: Version 11.2.0.4.0 - Production

        TCP/IP NT Protocol Adapter for Linux: Version 11.2.0.4.0 - Production

  Time: 21-OCT-2015 16:25:41

  Tracing not turned on.

  Tns error struct:

    ns main err code: 12541

   

TNS-12541: TNS:no listener

    ns secondary err code: 12560

    nt main err code: 511

   

TNS-00511: No listener

    nt secondary err code: 111

    nt OS err code: 0

Error 12541 received logging on to the standby

Check whether the listener is up and running.

PING[ARC2]: Heartbeat failed to connect to standby 'vlifesb'. Error is 12541.



此時,我們在Primary上進行事務操作。



SQL> insert into t_m select * from dba_objects where rownum<100;

99 rows inserted


SQL> commit;

Commit complete


SQL> select group#, sequence#, status from v$log;


    GROUP#  SEQUENCE# STATUS

---------- ---------- ----------------

         1         89 CURRENT

         2         87 INACTIVE

         3         88 INACTIVE



事務操作成功。如果我們嘗試重新啟動standby,是不被允許的。



SQL> SQL> shutdown immediate

ORA-01154: database busy. Open, close, mount, and dismount not allowed now


日誌:


Wed Oct 21 16:34:41 2015

Attempt to shut down Standby Database

Standby Database operating in NO DATA LOSS mode

Detected primary database alive, shutdown primary first, shutdown aborted



但是,切換日誌強制歸檔過程的時候,資料庫立即發現Standby存在問題,停庫。



SQL> alter system switch logfile;

alter system switch logfile

 

ORA-03113: 通訊通道的檔案結尾

程式 ID: 9478

會話 ID: 394 序列號: 33


Destination LOG_ARCHIVE_DEST_2 is UNSYNCHRONIZED

LGWR: All standby destinations have failed

******************************************************

WARNING: All standby database destinations have failed

WARNING: Instance shutdown required to protect primary

******************************************************

LGWR (ospid: 30597): terminating the instance due to error 16098

Wed Oct 21 16:43:44 2015

System state dump requested by (instance=1, osid=30597 (LGWR)), summary=[abnormal instance termination].

System State dumped to trace file /u01/app/oracle/diag/rdbms/vlife/vlife/trace/vlife_diag_30587_20151021164344.trc

Dumping diagnostic data in directory=[cdmp_20151021164344], requested by (instance=1, osid=30597 (LGWR)), summary=[abnormal instance termination].

Instance terminated by LGWR, pid = 30597



此時,standby端日誌資訊:



--Standby

Wed Oct 21 16:43:42 2015

Archived Log entry 85 added for thread 1 sequence 89 ID 0xfad4f44b dest 1:

Wed Oct 21 16:43:43 2015

Wed Oct 21 16:43:43 2015

RFS[20]: Possible network disconnect with primary databaseRFS[17]: Possible network disconnect with primary database



說明:在最大保護狀態的時候,如果Primary發現備庫傳輸日誌有問題,出於保護的必要,就會自動停機。


下面可以進行操作恢復,備庫首先恢復應用日誌狀態:



SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered



Wed Oct 21 16:46:19 2015

alter database recover managed standby database using current logfile disconnect from session


Attempt to start background Managed Standby Recovery process (vlifesb)

Wed Oct 21 16:46:19 2015

MRP0 started with pid=25, OS id=1495

MRP0: Background Managed Standby Recovery process started (vlifesb)

 started logmerger process

Wed Oct 21 16:46:24 2015

Managed Standby Recovery starting Real Time Apply

Parallel Media Recovery started with 4 slaves

Waiting for all non-current ORLs to be archived...

All non-current ORLs have been archived.

Media Recovery Log /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_21/o1_mf_1_89_c2gn1ylm_.arc

Media Recovery Waiting for thread 1 sequence 90

Completed: alter database recover managed standby database using current logfile disconnect from session



注意,此時第二個事務對應資料表t_m的資料已經發生變化。這說明之前雖然已經停止監聽活動,但是依賴之前的已經確立連線,還是將日誌傳輸過去。



SQL> select count(*) from t_m;


  COUNT(*)

----------

        99



嘗試啟動主庫:



[oracle@vLIFE-URE-OT-DB-PRIMARY trace]$ sqlplus /nolog


SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 21 16:48:23 2015


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


SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup

ORACLE instance started.


Total System Global Area 2471931904 bytes

Fixed Size                  2255752 bytes

Variable Size             738198648 bytes

Database Buffers         1711276032 bytes

Redo Buffers               20201472 bytes

Database mounted.

ORA-03113: end-of-file on communication channel

Process ID: 9617

Session ID: 580 Serial number: 5


Error 12541 received logging on to the standby

Check whether the listener is up and running.

LGWR: Error 12541 creating archivelog file 'vlifesb'

Crash Recovery Foreground: All standby destinations have failed

******************************************************

WARNING: All standby database destinations have failed

WARNING: Instance shutdown required to protect primary

******************************************************

USER (ospid: 9617): terminating the instance due to error 16098

System state dump requested by (instance=1, osid=9617), summary=[abnormal instance termination].

System State dumped to trace file /u01/app/oracle/diag/rdbms/vlife/vlife/trace/vlife_diag_9581_20151021164839.trc

Dumping diagnostic data in directory=[cdmp_20151021164839], requested by (instance=1, osid=9617), summary=[abnormal instance termination].

Instance terminated by USER, pid = 9617



mountopen的過程中,啟動被終止。這個是可以理解的,在Standby端,監聽器沒有啟動。



[oracle@vLIFE-URE-OT-DB-STANDBY ~]$ lsnrctl start


LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-OCT-2015 16:50:20


Copyright (c) 1991, 2013, Oracle.  All rights reserved.

(篇幅原因,有省略……

Service "vlifesb" has 1 instance(s).

  Instance "vlifesb", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully



此時,再次啟動資料庫主庫,操作成功。



SQL> startup

ORACLE instance started.


Total System Global Area 2471931904 bytes

Fixed Size                  2255752 bytes

Variable Size             738198648 bytes

Database Buffers         1711276032 bytes

Redo Buffers               20201472 bytes

Database mounted.

Database opened.



最後,從最大保護“退化”到最大效能模式。



SQL> alter database set standby database to maximize performance

  2  ;


Database altered


SQL> select name, open_mode, database_role, protection_mode from v$database;


NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE

--------- -------------------- ---------------- --------------------

VLIFE     READ WRITE           PRIMARY          MAXIMUM PERFORMANCE



5、結論


Oracle DG的三種模式,是與歸檔日誌傳輸機制緊密相關的。歸檔日誌傳輸確定了保護模式的基礎前提,透過alter database set操作定義了資料庫行為,特別是主庫工作行為。







About Me

...............................................................................................................................

● 本文作者:小麥苗,只專注於資料庫的技術,更注重技術的運用

● 本文在itpub(http://blog.itpub.net/26736162)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● QQ群:230161599     微信群:私聊

● 聯絡我請加QQ好友(646634621),註明新增緣由

● 於 2017-06-02 09:00 ~ 2017-06-30 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

...............................................................................................................................

拿起手機使用微信客戶端掃描下邊的左邊圖片來關注小麥苗的微信公眾號:xiaomaimiaolhr,掃描右邊的二維碼加入小麥苗的QQ群,學習最實用的資料庫技術。

【DG】DG的3種保護模式
DBA筆試面試講解
歡迎與我聯絡

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

相關文章