• oracle adg切换


    作者:广大

    1 主库转备库

    注意:原则上至多只能有一个主库,但是备库可以多个,所以需要先进行主库转备库操作。

    1.1 查看主库角色切换状态

    SYS@proe>select name,database_role,switchover_status from v$database;
    
    NAME                      DATABASE_ROLE    SWITCHOVER_STATUS
    ------------------------- ---------------- --------------------
    PROE                      PRIMARY          TO STANDBY
    

    1.2 正常主库切换备库命令

    SYS@proe>alter database commit to switchover to physical standby;
    
    Database altered.
    

    1.3 执行切换后的操作

    SYS@proe>shutdown abort
    ORACLE instance shut down.
    SYS@proe>startup mount;
    ORACLE instance started.
    # 查看此时角色切换状态
    SYS@proe>select name,database_role,switchover_status from v$database;
    
    NAME                      DATABASE_ROLE    SWITCHOVER_STATUS
    ------------------------- ---------------- --------------------
    PROE                      PHYSICAL STANDBY RECOVERY NEEDED
    # 查看角色保护模式和级别
    SYS@proe> select name,database_role,protection_mode,protection_level from v$database;
    
    NAME                      DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL
    ------------------------- ---------------- -------------------- --------------------
    PROE                      PHYSICAL STANDBY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
    

    1.4 异常切换命令

    "TO STANDBY"意味着主库此时可以切换为备库,如果状态为SESSION ACTIVE可以使用以下命令切换。然后执行上述切换后的操作。

    SYS@proe>alter database commit to switchover to physical standby with session shutdown;
    

    2 备库转主库

    2.1 查看备库角色切换状态

    SYS@stddb>select name,database_role,switchover_status from v$database;
    
    NAME      DATABASE_ROLE    SWITCHOVER_STATUS
    --------- ---------------- --------------------
    PROE      PHYSICAL STANDBY TO PRIMARY
    

    2.2 备库切换主库命令

    SYS@stddb>alter database commit to switchover to primary;
    
    Database altered.
    

    2.3 执行切换后的操作

    # 查看此时角色切换状态
    SYS@stddb>select name,database_role,switchover_status from v$database;
    
    NAME      DATABASE_ROLE    SWITCHOVER_STATUS
    --------- ---------------- --------------------
    PROE      PRIMARY          NOT ALLOWED
    # 查看角色保护模式和级别
    SYS@stddb>select name,database_role,protection_mode,protection_level from v$database;
    
    NAME      DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL
    --------- ---------------- -------------------- --------------------
    PROE      PRIMARY          MAXIMUM PERFORMANCE  UNPROTECTED
    # 备库切换为主库后实例状态
    SYS@stddb>select instance_name,status from v$instance;
    
    INSTANCE_NAME    STATUS
    ---------------- ------------
    stddb            MOUNTED
    # 将数据库启动到open
    SYS@stddb>alter database open;
    
    Database altered.
    # 再次查看转换后的角色保护模式及级别,可以看到和原来的主库一致。
    SYS@stddb>select database_role,protection_mode,protection_level from v$database;
    
    DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL
    ---------------- -------------------- --------------------
    PRIMARY          MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE
    

    3 启动现在备库日志应用服务

    原来的主库已经切换为备库,查看此时数据库打开模式

    SYS@proe>select name,open_mode from v$database;
    
    NAME                      OPEN_MODE
    ------------------------- --------------------
    PROE                      MOUNTED
    

    数据库启动到open

    SYS@proe>alter database open;
    
    Database altered.
    

    启动数据库的日志应用服务

    SYS@proe>alter database recover managed standby database using current logfile disconnect;
    Database altered.
    # 查看数据库打开模式
    SYS@proe>select name,open_mode from v$database;
    
    NAME                      OPEN_MODE
    ------------------------- --------------------
    PROE                      READ ONLY WITH APPLY
    

    一次完整的主备切换完成

    更多技术信息请查看云掣官网https://yunche.pro/?t=yrgw

  • 相关阅读:
    无限 debugger 能劝退 Spider Engineer 吗?原来我还没入门!
    Django系列5-请求和响应
    程序猿的中秋原来可以这样过
    老板也有生命周期
    Delphi组件源码:HTML Component Library 3.9
    【数学建模】——【新手小白到国奖选手】——【学习路线】
    ai智能写作软件哪个好-AI智能写作软件的类型标准
    react-router-dom V6 路由
    解决 idea maven依赖引入失效,无法正常导入依赖问题
    智慧城市应用数据治理的作用有哪些?
  • 原文地址:https://blog.csdn.net/weixin_43756308/article/details/140442323