计划切换

Oracle 数据库以两个角色之一运行:主角色或备用角色。Data Guard 可帮助您使用切换或故障转移更改数据库的角色:

  • 切换是主数据库与其备用数据库之一之间的角色逆转。切换可保证不丢失数据,通常用于计划维护主系统。切换期间,主数据库将转换为备用角色,备用数据库将转换为主角色。
  • 当主数据库(Oracle RAC 主数据库的所有实例)失败或变得不可访问并且某个备用数据库转换为接管主角色时,将执行故障转移。故障转移可能导致数据丢失,也可能不会导致数据丢失,具体取决于故障转移时有效的保护模式。

将主数据库从本地切换到 OCI

当您有计划的活动(如维护)时,可以将 Oracle Cloud Infrastructure (OCI) 中的数据库设为数据丢失为零的主数据库。切换是在内部部署数据库上启动并在云中的数据库实例上完成的计划事件。

  1. 使用 sys 用户名和口令登录内部部署数据库上的 DGMGRL 会话。
    DGMRGL> connect
  2. 在本地数据库上,验证备用数据库是否已准备好切换和故障转移。
    在此示例中,主数据库为 db1,备用数据库(StandbyDatabaseOCIInstanceDB1_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) 数据库实例之间前后切换主数据库。