驗證 DR 整備度

複查災害復原就緒的最佳做法,並驗證已計畫與未計畫事件的災害復原設定。

關於 DR 整備度

複查災害復原 (DR) 的最佳做法。

您可以使用 Active Data Guard 將唯讀工作負載卸載至待命資料庫,以提供持續、應用程式層次的驗證,讓待命資料庫可以開始實際執行。除了連續 Oracle Data Guard 套用處理作業執行的 Oracle 區塊層次驗證之外,還提供保證層次。

您可以使用快照待命資料庫建立實際環境執行資料庫的複本,以供開發和測試之用。定期將待命資料庫置於讀取/寫入模式 (使用「資料保全快照待命」),以驗證其整備度以支援讀寫實際環境執行工作負載。快照待命也可用於修正程式和升級的最終功能和效能測試,因為 DR 系統大小與實際環境執行系統類似。「快照待命資料庫」會繼續從存檔供以後使用的主要資料庫接收 redo,這可隨時提供資料保護。不過,如果進行測試時需要容錯移轉,復原時間 (RTO) 會以將「快照待命」轉換回待命資料庫所需的時間長度來延長。當待命資料庫處於快照模式 (保留從主要實際環境執行資料庫接收的存檔重做供以後使用,以及快照待命資料庫產生的目前重做和倒溯日誌) 時,快速復原區域需要額外的儲存體。

下列是一些使用快照待命資料庫的優點:

  • 它提供實際環境執行資料庫的精確複本以進行開發和測試,同時隨時維護資料保護。您可以使用 Oracle Real Application Testing 選項來擷取主要資料庫工作負載,然後在快照待命資料庫上重新執行以進行測試。
  • 透過轉換成實體待命並重新同步,便可輕鬆地重新整理以包含目前的生產環境資料。

將待命資料庫轉換成快照待命資料庫

當您需要實際環境執行資料庫的正確複本時,可以使用 Oracle Data Guard Broker 將實體待命資料庫轉換成快照待命資料庫,並驗證容錯移轉。

快照待命資料庫是從實體待命資料庫建立的可完全更新待命資料庫。在快照待命資料庫上,會收到 redo 資料,但要等到快照待命資料庫轉換回實體待命資料庫後才會套用。

Oracle Data Guard 命令行介面 (DGMGRL) 可讓您直接從命令行介面管理 Oracle Data Guard 中介組態及其各種成員。

  1. 使用 sys 使用者名稱和密碼登入待命資料庫執行處理上的 DGMGRL 階段作業。
    DGMRGL> connect
    Username: sys
    Password:
    輸出將與下列類似:
    Connected to "ORCLCDB_iad1s3"
    Connected as SYSDBA.
  2. 將實體待命資料庫轉換成快照待命資料庫。
    DGMGRL> convert database standby_database_unique_name (standbyDB) to snapshot standby;
    當轉換完成時,輸出將會有類似以下的行:
    Converting database "standby_database_unique_name" to a Snapshot Standby database, please wait...
    Database "standby_database_unique_name" converted successfully
  3. 檢視組態以驗證轉換。
    DGMGRL> show configuration;
    輸出將與下列類似:
    Configuration - onpremdr
      Protection Mode: MaxPerformance
      Members:
      orclcdb_iad1s3 - Primary database
        orclcdb        - Physical standby database 
    Fast-Start Failover:  Disabled
    Configuration Status:
    SUCCESS   (status updated 26 seconds ago)
  4. 將快照待命資料庫轉換回實體待命資料庫。
    DGMGRL> convert database standby_database_unique_name to physical standby;
    輸出將與下列類似:
    Converting database "orclcdb" to a Physical Standby database, please wait...
    Operation requires a connection to database "orclcdb_iad1s3"
    Connecting ...
    Connected to "ORCLCDB_IAD1S3"
    Connected as SYSDBA.
    Operation requires shut down of instance "ORCLCDB" on database "orclcdb"
    Shutting down instance "ORCLCDB"...
    Connected to "ORCLCDB"
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    Operation requires start up of instance "ORCLCDB" on database "orclcdb"
    Starting instance "ORCLCDB"...
    Connected to an idle instance.
    ORACLE instance started.
    Connected to "ORCLCDB"
    Database mounted.
    Connected to "ORCLCDB"
    Continuing to convert database "orclcdb" ...
    Database "orclcdb" converted successfully
  5. 檢視組態以驗證轉換。
    DGMGRL> show configuration;
    輸出將與下列類似:
    Configuration - onpremdr
    
      Protection Mode: MaxPerformance
      Members:
      orclcdb_iad1s3 - Primary database
        orclcdb        - Physical standby database 
          Warning: ORA-16854: apply lag could not be determined
    
    Fast-Start Failover:  Disabled
    
    Configuration Status:
    WARNING   (status updated 11 seconds ago)

設定 Oracle Data Guard 參數

執行切換之前,請先在主要和待命資料庫執行處理上設定 Oracle Data Guard 參數。

  1. 在內部部署主要資料庫上,檢查系統變更編號 (SCN)。
    select standby_became_primary_scn from v$database;
    輸出將與下列類似:
    STANDBY_BECAME_PRIMARY_SCN
    --------------------------
                                  0
  2. 確認未在主要資料庫啟用倒溯。
    select flashback_on from v$database;
    輸出將與下列類似:
    FLASHBACK_ON
    ------------------
    NO
  3. 在內部部署執行處理上,使用與 Oracle 使用者相同的主要資料庫名稱建立復原目錄。
    在此範例中,ORCLCDB 是內部部署資料庫的名稱。
    [oracle@bastion dbhome_1]$ cd /opt/oracle/
    [oracle@bastion oracle]$ mkdir recovery
    [oracle@bastion oracle]$ cd recovery/
    [oracle@bastion recovery]$ mkdir ORCLCDB
    [oracle@bastion oracle]$ cd ORCLCDB /
    確認完整路徑。
    $ pwd
    /opt/oracle/recovery/ORCLCDB
  4. 設定 DB_RECOVERY_FILE_DEST_SIZE 參數的大小以符合您的資料庫大小。
    下列範例使用 20G 作為範例資料大小。根據您的資料庫設定資料大小。
    SQL> alter system set DB_RECOVERY_FILE_DEST_SIZE=20G;
    System altered
  5. 定義您稍早建立之目錄的資料庫復原檔案目的地。
    SQL> alter system set db_recovery_file_dest = '/opt/oracle/recovery/on_premises_SID';
    System altered
  6. 在主要資料庫啟用倒溯。
    SQL> alter database flashback on;
    Database altered
  7. 確認已啟用 (開啟) 資料庫倒溯。
    SQL> select flashback_on from v$database;
    輸出將與下列類似:
    FLASHBACK_ON
    ------------------
    YES
  8. 判斷是否已在雲端 OCI 待命資料庫上啟用倒溯。
    SQL> select flashback_on from v$database;
    輸出將與下列類似:
    FLASHBACK_ON
    ------------------
    NO
  9. 查詢雲端中待命資料庫的開啟模式狀態。
    SQL> select open_mode from v$database;
    輸出將與下列類似:
    OPEN_MODE
    -------------------- 
    MOUNTED
  10. 在雲端的資料庫執行處理上設定倒溯。
    SQL> alter database recover managed standby database cancel;
    Database altered
  11. 查詢雲端中待命資料庫的開啟模式狀態。
    SQL> select open_mode from v$database;
    輸出將與下列類似:
    OPEN_MODE
    -------------------- 
    MOUNTED
  12. 啟用待命資料庫的倒溯。
    SQL> alter database flashback on;
    Database altered
  13. 中斷待命資料庫與階段作業的連線。
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
    Database altered
  14. 確認已啟用 (開啟) 資料庫倒溯。
    SQL> select flashback_on from v$database;
    FLASHBACK_ON
    ------------------
    YES
  15. 顯示保留參數。
    SQL> show parameter_retention;
    輸出將與下列類似:
    NAME				     TYPE	 VALUE
    ------------------------------------ ----------- ------------------------------
    db_flashback_retention_target	     integer	 1440
    undo_retention			      integer	 900

將主要資料庫從內部部署切換至 OCI

當您進行計畫性活動 (例如維護) 時,可以將 Oracle Cloud Infrastructure (OCI) 中的資料庫設為主要資料庫,讓資料遺失為零。切換是在內部部署資料庫上起始,並在雲端的資料庫執行處理上完成的計畫事件。

  1. 使用 sys 使用者名稱和密碼登入內部部署資料庫上的 DGMGRL 階段作業。
    DGMRGL> connect
  2. 在內部部署資料庫上,驗證待命資料庫是否已準備好進行切換和容錯移轉。
    在此範例中,主要資料庫是 orclcdb,而待命資料庫是 orclcdb_iadls3
    DGMGRL> validate database orclcdb_iad1s3 (StandbyDatabaseOCIInstance)
    輸出將與下列類似:
    Database Role:     Physical standby database
      Primary Database:  orclcdb
    
      Ready for Switchover:  Yes
      Ready for Failover:    Yes (Primary Running)
    
      Managed by Clusterware:
        orclcdb       :  NO             
        orclcdb_iad1s3:  NO             
        Validating static connect identifier for the primary database orclcdb...
        The static connect identifier allows for a connection to database "orclcdb".
    
      Log Files Cleared:
        orclcdb Standby Redo Log Files:         Cleared
        orclcdb_iad1s3 Online Redo Log Files:   Not Cleared
        orclcdb_iad1s3 Standby Redo Log Files:  Available
    
      Current Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (orclcdb)               (orclcdb_iad1s3)                     
        1         3                       2                       Insufficient SRLs
    
      Future Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (orclcdb_iad1s3)        (orclcdb)                            
        1         3                       0                       Insufficient SRLs
        Warning: standby redo logs not configured for thread 1 on orclcdb
  3. 在內部部署 (主要) 資料庫上,執行命令以切換至待命資料庫。
    DGMGRL> switchover to orclcdb_iad1s3 (StandbyDatabaseOCIInstance)
    輸出將與下列類似:
    Performing switchover NOW, please wait...
    New primary database "orclcdb_iad1s3" is opening...
    Operation requires start up of instance "ORCLCDB" on database "orclcdb"
    Starting instance "ORCLCDB"...
    Connected to an idle instance.
    ORACLE instance started.
    Connected to "ORCLCDB"
    Database mounted.
    Database opened.
    Connected to "ORCLCDB"
    Switchover succeeded, new primary is "orclcdb_iad1s3"
  4. 在內部部署資料庫上,顯示組態狀態。
    DGMGRL> show configuration
    輸出將與下列類似:
    Configuration - onpremdr
    
      Protection Mode: MaxPerformance
      Members:
      orclcdb_iad1s3 - Primary database
      orclcdb        - Physical standby database 
    
    Fast-Start Failover:  Disabled
    
    Configuration Status:
    SUCCESS   (status updated 70 seconds ago)
  5. 在雲端的資料庫中,判斷開啟模式狀態。
    SQL> select open_mode from v$database;
    輸出將與下列類似:
    OPEN_MODE
    -------------------- 
    READ WRITE
  6. 在內部部署資料庫上,決定開啟模式狀態。
    SQL> select open_mode from v$database;
    輸出將與下列類似:
    OPEN_MODE
    -------------------- 
    READ ONLY WITH APPLY
雲端中的待命資料庫現在是主要資料庫。

將主要資料庫從 OCI 切換回內部部署

Oracle Cloud Infrastructure (OCI) 中的資料庫執行處理設為主要資料庫之後,請使用 OCI 資料庫執行處理上的 Oracle Data Guard 命令行介面 (DGMGRL) 來切換回您的內部部署資料庫,並再次將您的內部部署資料庫設為主要資料庫。

  1. 驗證雲端中主要資料庫的資料庫角色。
    在此範例中,ORCLCDB 是內部部署資料庫的名稱,而 orclcdb_iad1s3 是雲端中資料庫執行處理的名稱。
    DGMGRL> validate database orclcdb;
    輸出可能與下列類似:
    Database Role: Physical standby database
      Primary Database: orclcdb_iad1s3
    
      Ready for Switchover:  Yes
      Ready for Failover:    Yes (Primary Running)
    
      Managed by Clusterware:
        orclcdb_iad1s3:  NO             
        orclcdb       :  NO             
        Validating static connect identifier for the primary database orclcdb_iad1s3...
    Unable to connect to database using (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.0.2.1)(PORT=1539)))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB_iad1s3_DGMGRL.sub08120021431.onpremocidrvcn.example.com)(INSTANCE_NAME=ORCLCDB)(SERVER=DEDICATED)(STATIC_SERVICE=TRUE)))
    ORA-12541: TNS:no listener
    
    Failed.
        Warning: Ensure primary database's StaticConnectIdentifier property
        is configured properly so that the primary database can be restarted
        by DGMGRL after switchover
    
      Log Files Cleared:
        orclcdb_iad1s3 Standby Redo Log Files:  Cleared
        orclcdb Online Redo Log Files:          Not Cleared
        orclcdb Standby Redo Log Files:         Available
    
      Current Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (orclcdb_iad1s3)        (orclcdb)                            
        1         3                       2                       Insufficient SRLs
    
      Future Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (orclcdb)               (orclcdb_iad1s3)                     
        1         3                       2                       Insufficient SRLs

    如果您收到靜態連線 ID 警告訊息,請複查組態參數、SID 服務名稱、主機 IP 位址或連接埠位址。

  2. 使用 sys 使用者名稱和密碼登入 DGMGRL 階段作業。
    DGMRGL> connect
  3. 複查內部部署資料庫的靜態連線 ID。
    DGMGRL> show database orclcdb StaticConnectIdentifier
    複查輸出以確認 StaticConnectIdentifier 參數是正確的。範例如下:
    DGMGRL> show database orclcdb StaticConnectIdentifier
      StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.0.2.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB)(INSTANCE_NAME=ORCLCDB)(SERVER=DEDICATED)(STATIC_SERVICE=TRUE)))'
  4. 複查雲端中資料庫執行處理的靜態連線 ID。
    DGMGRL> show database orclcdb_iad1s3 StaticConnectIdentifier
      StaticConnectIdentifier = 
    '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.10.30.3)(PORT=1539)
    ))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB_iad1s3_DGMGRL.sub08120021431.onpremocidrvcn.examplevcn.com) 
    INSTANCE_NAME=ORCLCDB)(SERVER=DEDICATED)))'
    請複查輸出以確認 StaticConnectIdentifier 參數 (如連接埠號碼和服務名稱) 正確。
  5. 更正任何 StaticConnectIdentifier 參數,例如連接埠號碼和服務名稱。
    編輯特性時,您必須使用 Oracle Data Guard 命令行介面 (DGMGRL),而不需分行符號。此範例會更正雲端中資料庫執行處理的連接埠號碼和服務名稱 (orclcdb_iad1s3)。
    DGMGRL> edit database 'orclcdb_iad1s3' set property StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.0.2.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB)(INSTANCE_NAME=ORCLCDB)(SERVER=DEDICATED)))';
    Property "staticconnectidentifier" updated
  6. 驗證雲端中的資料庫執行處理。
    DGMGRL> validate database orclcdb_iad1s3;
    輸出將與下列類似:
    Database Role:    Primary database
      Ready for Switchover:  Yes
    
      Managed by Clusterware:
        orclcdb_iad1s3:  NO             
        Validating static connect identifier for the primary database orclcdb_iad1s3...
        The static connect identifier allows for a connection to database "orclcdb_iad1s3".
  7. 驗證內部部署資料庫。
    DGMGRL> validate database orclcdb;
    輸出將與下列類似:
    Database Role:     Physical standby database
      Primary Database:  orclcdb_iad1s3
      Ready for Switchover:  Yes
      Ready for Failover:    Yes (Primary Running)
    
      Managed by Clusterware:
        orclcdb_iad1s3:  NO             
        orclcdb       :  NO             
        Validating static connect identifier for the primary database orclcdb_iad1s3...
        The static connect identifier allows for a connection to database "orclcdb_iad1s3".
    
      Standby Apply-Related Information:
        Apply State:      Running
        Apply Lag:        2 seconds (computed 7 seconds ago)
        Apply Delay:      0 minutes
    
      Log Files Cleared:
        orclcdb_iad1s3 Standby Redo Log Files:  Cleared
        orclcdb Online Redo Log Files:          Not Cleared
        orclcdb Standby Redo Log Files:         Available
    
      Current Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (orclcdb_iad1s3)        (orclcdb)                            
        1         3                       2                       Insufficient SRLs
    
      Future Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (orclcdb)               (orclcdb_iad1s3)                     
        1         3                       2                       Insufficient SRLs
  8. 顯示並複查組態。
    DGMGRL> show configuration;
    輸出將與下列類似:
    Configuration - onpremdr
    
      Protection Mode: MaxPerformance
      Members:
      orclcdb_iad1s3 - Primary database
        orclcdb        - Physical standby database 
    
    Fast-Start Failover:  Disabled
    
    Configuration Status:
    SUCCESS   (status updated 27 seconds ago)
  9. 從 OCI 中的資料庫執行處理切換至內部部署資料庫。
    DGMGRL> switchover to orclcdb;
    輸出將與下列類似:
    Performing switchover NOW, please wait...
    Operation requires a connection to database "orclcdb"
    Connecting ...
    Connected to "ORCLCDB"
    Connected as SYSDBA.
    New primary database "orclcdb" is opening...
    Operation requires start up of instance "ORCLCDB" on database "orclcdb_iad1s3"
    Starting instance "ORCLCDB"...
    Connected to an idle instance.
    ORACLE instance started.
    Connected to "ORCLCDB_iad1s3"
    Database mounted.
    Database opened.
    Connected to "ORCLCDB_iad1s3"
    Switchover succeeded, new primary is "orclcdb"
    掛載資料庫之後,您可能會收到下列警告:
    ORA-16000: database or pluggable database open for read-only access  
    
    Please complete the following steps to finish switchover:
           start up instance "ORCLCDB" of database "orclcdb" 

    您可以忽略警告並繼續下一個步驟。

  10. 在待命資料庫 (現在是主要資料庫) 上,連線並複查組態。
    DGMGRL> show configuration;
    輸出將與下列類似:
    Configuration - onpremdr
    
      Protection Mode: MaxPerformance
      Members:
      orclcdb        - Primary database
        orclcdb_iad1s3 - Physical standby database 
    
    Fast-Start Failover:  Disabled
    
    Configuration Status:
    SUCCESS   (status updated 86 seconds ago)
  11. 在主要資料庫執行處理 ORCLCDB 上,確認模式為 read write
    SQL> select database_role, open_mode from v$database;
    DATABASE_ROLE	 OPEN_MODE
    ---------------- --------------------
    PRIMARY 	   READ WRITE
  12. (選擇性) 您可以使用 verbose 命令來顯示完整的堆疊傾印,包括角色、狀態、執行處理、特性以及「警示」日誌和「資料保全中介」日誌的位置。
    DGMGRL> show database verbose orclcdb

您可以在內部部署資料庫和 OCI 資料庫執行處理之間來回切換主要資料庫。