DG(1)Performing a Failover to a Physical Standby Database

本文详细介绍了使用Oracle11g物理备库在主库无法启动到mount状态时进行失败切换的方法,包括刷新未发送的redo日志、处理缺失日志、停止redo应用、完成接收redo数据应用、验证备库准备情况、切换备库为新主库及后续操作等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    Oracle 11g官方文档的记录整理,用于物理Standby数据库的Failover.

   其中要注意,alter system flush redo是11g的新特性。


Step 1 Flush any unsent redo from the primary database to the target standby database.

    alter system flush redo to target_db_name
 说明:
  For target_db_name,specify the DB_UNIQUE_NAME of the standby database that is to receive the redo flushed from the primary database.
  This statement flushes any unsend redo from the primary database to standby database,and waits for that redo to be applied to the standby database;
  alter system flush redo 能在failover(失败切换)时,可以将没发送出去的redo log从主库发送到备库.
  并且确认备库接收到redo日志并应用后,才返回.前提是主库要能启动到mount状态,这样命令能保证主数据库不会有数据丢失.
如果主库不能启动到mount状态:
 1. 从备库查出每个日志线程的最高日志序号
        SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY thread#) AS LAST from V$ARCHIVED_LOG; 
 2. 将主库中没有应用的日志复制到备库上,
    3. 在备库注册新复制过来的日志.
        ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';


Step 2 处理缺失的日志

   1.找出缺失的,不一致的日志来应用.  
       SELECT thread#,low_sequence#,high_sequence# FROM v$archive_gap;
 2. 将主库中没有应用的日志复制到备库上
    3. 在备库注册新复制过来的日志.
   ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1'; 
    4. 再重复执行查询,找出下一次中断. 
     原因是v$archive_gap不能一次列出所有,一次只会显示一个当前的中断.


Step 3 Stop Redo Apply

   alter database recover managed standby database cancel;


Step 4 Finish applying all received redo data

    alter database recover managed standby database finish;
   注意:
         假如有问题无法解决,用下面的这个命令,仍然可以将其转为主库,但可能会有数据丢失.
   执行完后,直接到Step 7去执行alter database open;等后续步骤即可.
   没问题,则可省略这条命令.
           alter database activate physical standby database;


Step 5 Verify that the target standby database databse is ready to become a primary database.

      col OPEN_MODE format a10
      col DB_UNIQUE_NAME format a20
      SELECT NAME,OPEN_MODE,DB_UNIQUE_NAME ,switchover_status FROM v$database;

  假如switchover_status不是返回的TO PRIMARY或SESSIONS ACTIVE则说明备库还没有准备好
    转成主库.需要检查是否有日志没有应用.处理后,再查询,一直到返回TO PRIMARY或SESSIONS ACTIVE为止.


Step 6 Switch the physical standby database to the primary role

    alter database commit to switchover to primary with session shutdown;

    注意:如果不带with session shutdown 则,如果数据库当前有其他活动连接则无法完成切换。


Step 7.Open the new primary database

    alter database open;


Step 8.Back up the new primary database.

    Oracle recommends that a full backup be taken of the new primary database.


Step 9.Restart Redo Apply if it has stopped at any of the other physical standby database

    in your Data Guard configuration.

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

      其中 using current logfile 的意思是,当备库收到传过来的日志后,会尽快完成恢复。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值