• 手工failed over(非dgbroker管理)


    环境:
    OS:Centos 7
    DB:11.2.0.4

    一主两从架构:
    主库:slnngk
    从库1:slavea
    从库2:slaveb

    1.主从库上开启flashback
    这里主从库上都要开启flashback,如果不开启flashback的话,DG就要重新搭建
    查看是否开启flashback
    SQL> select t.FLASHBACK_ON from v$database t;

    FLASHBACK_ON
    ------------------
    YES

    具体开启部署请参考:
    https://www.cnblogs.com/hxlasky/p/15221695.html

    2.由于主库已经不可访问,我们所有的操作都在备库完成
    我们假设主库slnngk所在机器已经宕机,我们将从库slavea提升为主库,下面的操作都在从库slavea上操作
    SQL> alter database recover managed standby database cancel;
    SQL> alter database recover managed standby database finish force;
    SQL> select database_role from v$database;

    DATABASE_ROLE
    ----------------
    PHYSICAL STANDBY

    SQL> alter database commit to switchover to primary;
    alter database commit to switchover to primary
    *
    ERROR at line 1:
    ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected

    解决办法:
    SQL> alter database commit to switchover to primary with session shutdown;

    Database altered.


    SQL> alter database open;

    3.尝试在新主库上做些操作
    比如创建表,并写入数据
    connect hxl/oracle
    create table tb_test as select * from dba_objects;

    4.现在利用flashback重建DG
    在现在的主库slavea上执行如下查询,找到standby_became_primary_scn的值,下面原来的主库slnngk恢复后使用该值进行flashbak

    SQL> select to_char(standby_became_primary_scn) from v$database;

    TO_CHAR(STANDBY_BECAME_PRIMARY_SCN)
    ----------------------------------------
    2662627


    5.原来的主库slnngk进行flashback
    等原来的主库机器启动后
    SQL> startup mount
    SQL> flashback database to scn 2662627; ##这个值为在新主库slavea上查询到的SCN值
    SQL> alter database convert to physical standby;
    SQL> shutdown immediate
    SQL> startup
    SQL> alter database recover managed standby database using current logfile disconnect from session;

    6.检查第二个从库slaveb的日志使用情况

    上面slnngk已经变成了从库,那么第二个从库slaveb是什么一个状态呢,我们查询下日志应用情况

    SQL> select process,status from v$managed_standby;

    PROCESS STATUS
    --------- ------------
    ARCH CLOSING
    ARCH CONNECTED
    ARCH CONNECTED
    ARCH CLOSING
    RFS IDLE
    RFS IDLE
    RFS IDLE
    RFS IDLE
    MRP0 APPLYING_LOG
    RFS IDLE
    RFS IDLE

    11 rows selected.

    因为从库slabea这里之前设置了如下参数,变成主库后会自动将归档日志应用到从库slaveb

    SQL> show parameters log_archive_dest_2;
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    log_archive_dest_2                   string      service=tnsslnngk async valid_
                                                     for=(online_logfiles,primary_r
                                                     ole) db_unique_name=slnngk
    
    
    SQL> show parameters log_archive_dest_3;
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    log_archive_dest_3                   string      service="tnsslaveb", LGWR ASYN
                                                     C NOAFFIRM delay=0 optional co
                                                     mpression=disable max_failure=
                                                     0 max_connections=1 reopen=300
                                                      db_unique_name="slaveb" net_t
                                                     imeout=30, valid_for=(all_logf
                                                     iles,primary_role)

    若是没有设置归档到第二个从库slaveb的情况下,需要在新的主库slavea上执行
    alter system set log_archive_dest_3= 'service=tnsslaveb async valid_for=(online_logfiles,primary_role) db_unique_name=slaveb' scope=both;
    alter system set log_archive_dest_state_3=enable scope=both;

    这个时候第二个从库slaveb会自动应用新主库生成的归档日志.

    --The End --

  • 相关阅读:
    Spring事务管理
    Spring Bean装配(下)——注解
    Spring Bean装配(上)
    Spring入门篇
    Spring入门篇——AOP基本概念
    计算机组成原理(1)——系统概述
    浏览器缓存 总结
    React-router 4 总结
    Redux 总结
    操作系统位数 的 概念(转)
  • 原文地址:https://www.cnblogs.com/hxlasky/p/15222403.html
Copyright © 2020-2023  润新知