計畫切換

Oracle 資料庫會以主要或待命這兩個角色之一運作。「資料保全」可協助您使用切換或容錯移轉來變更資料庫的角色:

  • 切換是主要資料庫與其其中一個待命資料庫之間的角色反轉。切換可保證不會遺失資料,通常是針對主要系統的計畫性維護所完成。進行切換時,主要資料庫會轉換成待命角色,待命資料庫則會轉換成主要角色。
  • 當主要資料庫 (Oracle RAC 主要資料庫的所有執行處理) 失敗或無法連線,且其中一個待命資料庫轉換成接管主要角色時,就會進行容錯移轉。容錯移轉可能會 (也可能不會) 根據容錯移轉時的有效保護模式而遺失資料。

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

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

  1. 使用 sys 使用者名稱和密碼登入內部部署資料庫上的 DGMGRL 階段作業。
    DGMRGL> connect
  2. 在內部部署資料庫上,驗證待命資料庫是否已準備好進行切換和容錯移轉。
    在此範例中,主要資料庫為 db1,待命資料庫 (StandbyDatabaseOCIInstance ) 為 DB1_phx3g7
    DGMGRL> validate database DB1_phx3g7
    輸出看起來會像下面這樣:
    Database Role:     Physical standby database
      Primary Database:  db1
    
      Ready for Switchover:  Yes
      Ready for Failover:    Yes (Primary Running)
    
      Managed by Clusterware:
        db1       :  YES             
        db1_phx3g7:  YES   
              
    Standby Apply-Related Information:
        Apply State:      Running
        Apply Lag:        17 minutes 6 seconds (computed 42 seconds ago)
        Apply Delay:      0 minutes
      Current Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (db1)                   (db1_phx3g7)                         
        1         2                       0                       Insufficient SRLs
        Warning: standby redo logs not configured for thread 1 on db1_phx3g7
        2         2                       0                       Insufficient SRLs
        Warning: standby redo logs not configured for thread 2 on db1_phx3g7
      Future Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (db1_phx3g7)            (db1)                                
        1         2                       0                       Insufficient SRLs
        Warning: standby redo logs not configured for thread 1 on db1
        2         2                       0                       Insufficient SRLs
        Warning: standby redo logs not configured for thread 2 on db1
  3. 驗證主要資料庫。
    DGMGRL> validate database 'DB1';
    輸出看起來會像下面這樣:
    Database Role:    Primary database
      Ready for Switchover:  Yes
      Managed by Clusterware:
        db1:  YES    
  4. 驗證待命資料庫。
    DGMGRL> validate database 'DB1_phx3g7';
    輸出看起來會像下面這樣:
    
    Database Role:     Physical standby database  
    Primary Database:  db1  
    Ready for Switchover:  Yes  
    Ready for Failover:    Yes (Primary Running)  
    Managed by Clusterware:
        db1       :  YES                
        db1_phx3g7:  YES              
    Standby Apply-Related Information:
        Apply State:      Running
        Apply Lag:        32 minutes 12 seconds (computed 40 seconds ago)
        Apply Delay:      0 minutes  
    Current Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status
                  (db1)                   (db1_phx3g7)
         1         2                       0                       Insufficient SRLs
        Warning: standby redo logs not configured for thread 1 on db1_phx3g7
        2         2                       0                       Insufficient SRLs     
        Warning: standby redo logs not configured for thread 2 on db1_phx3g7
    
    Future Log File Groups Configuration:
        Thread #  Online Redo Log Groups  Standby Redo Log Groups Status       
                  (db1_phx3g7)            (db1)                                
        1         2                       0                       Insufficient SRLs
        Warning: standby redo logs not configured for thread 1 on db1
        2         2                       0                       Insufficient SRLs
        Warning: standby redo logs not configured for thread 2 on db1
  5. 在內部 (主要) 資料庫上,執行命令以切換至待命資料庫。
    DGMGRL> switchover to db1_phx3g7;
    輸出看起來會像下面這樣:
    Performing switchover NOW, please wait...
    Operation requires a connection to database "db1_phx3g7"
    Connecting ...
    Connected to "DB1_phx3g7"
    Connected as SYSDBA.
    New primary database "db1_phx3g7" is opening...
    Oracle Clusterware is restarting database "db1" ...
    Connected to "db1"
    Connected to "db1"
    Switchover succeeded, new primary is "db1_phx3g7"
  6. 在內部部署資料庫上,顯示組態狀態。
    DGMGRL> show configuration
    輸出看起來會像下面這樣:
    Configuration - onpremexadr
    
      Protection Mode: MaxPerformance
      Members:
      db1_phx3g7 - Primary database
          db1        - Physical standby database 
    
    Warning: ORA-16809: multiple warnings detected for the memberFast-Start
            Failover:  Disabled
    Configuration Status:
    WARNING   (status updated 35 seconds ago)
  7. 在主要內部部署 Oracle Exadata Database Machine 上,選取開啟模式。
    SQL> select open_mode from v$database;
    輸出看起來會像下面這樣:
    OPEN_MODE
    -------------------- 
    MOUNTED
  8. 在雲端的 Oracle Database Exadata Cloud Service 資料庫上,確認資料庫是 READ WRITE。
    SQL> select open_mode from v$database;
    輸出看起來會像下面這樣:
    OPEN_MODE
    -------------------- 
    READ WRITE
雲端 Oracle Database Exadata Cloud Service 上的資料庫是主要資料庫。

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

Oracle Cloud Infrastructure (OCI) 中將資料庫執行處理設為主要資料庫之後,請在 Oracle Database Exadata Cloud Service 中的 OCI 資料庫執行處理上使用 Oracle Data Guard 命令行介面 (DGMGRL) 來切換回來重新將企業內部部署資料庫設為主要資料庫。

  1. 從 OCI 中的資料庫執行處理切換至內部部署資料庫。
    DGMGRL> switchover to db1;
    輸出與下列類似:
    Performing switchover NOW, please wait...
    Operation requires a connection to database "db1"
    New primary database "db1" is opening...
    Oracle Clusterware is restarting database "db1_phx3g7" ...
    Connected to "DB1_phx3g7"
    Connected to "DB1_phx3g7"
    Switchover succeeded, new primary is "db1"
  2. 在內部部署 Oracle Exadata Database Machine 上,連線並複查組態。
    DGMGRL> show configuration;
    輸出與下列類似:
    Configuration - onpremexadr
    
      Protection Mode: MaxPerformance
      Members:
      db1        - Primary database
      Warning: ORA-16809: multiple warnings detected for the member
        db1_phx3g7 - Physical standby database 
          Error: ORA-12650: No common encryption or data integrity algorithm
    Fast-Start Failover:  Disabled
    Configuration Status:
    ERROR   (status updated 899 seconds ago)
  3. 在雲端的 Oracle Database Exadata Cloud Service 資料庫上,建立測試災害復原表格。
    SQL> create table testdr (a number , b number);
    Table created.
    SQL> desc testdr;
     Name                                        Null?    Type
     ----------------------------------------- -------- ----------------------------
     A                                          NUMBER
     B                                          NUMBER
  4. 結束 SQL。
    SQL> exit
  5. 在主要內部部署 Oracle Exadata Database Machine 上,以 sysdba 身分登入並檢視 testdr 表格。
    $ sqlplus / as sysdba
    SQL> desc testdr;
    
     Name                                        Null?    Type
     ----------------------------------------- -------- ----------------------------
     A                                          NUMBER
     B                                          NUMBER
  6. 在主要內部部署 Oracle Exadata Database Machine 上,顯示並複查組態。
    DGMGRL> show configuration;
    輸出與下列類似:
    Configuration - onpremexadr
    
      Protection Mode: MaxPerformance
      Members:
    db1        - Primary database
        db1_phx3g7 - Physical standby database 
          Warning: ORA-16809: multiple warnings detected for the member
    Fast-Start Failover:  Disabled
    Configuration Status:
    WARNING   (status updated 36 seconds ago)

您可以在內部部署資料庫與 Oracle Database Exadata Cloud Service (OCI) 資料庫執行處理之間來回切換主要資料庫。