设为首页 收藏本站
查看: 823|回复: 0

[经验分享] Implement Oracle Datagurad Failover

[复制链接]

尚未签到

发表于 2018-9-22 07:21:49 | 显示全部楼层 |阅读模式
  生产环境中,可能会有各种各样的原因导致数据库不能提供服务,例如数据库库的硬件故障,操作系统故障或软件bug,人为的失误(例如rm -rf /)等,在这种情况下,dataguard显得尤为重要,当主库不可用的时候,可以将备库failover成主库继续提供服务,failover和switchover不同的是,执行failover后,原有的dataguard配置将会失效且有可能会丢失部分数据,所以在生产环境中能用switchover解决的问题则应尽量采用switchover!switchover执行过程参考:http://ylw6006.blog.51cto.com/470441/849829
  一:使用sql命令执行failover
  
1:查看当前的主库是dg1,物理备库为dg2,将主库关闭,模拟主库故障
  


  • [oracle@dg2 ~]$ dgmgrl /
  • DGMGRL for Linux: Version 11.2.0.3.0 - 64bit Production
  • Copyright (c) 2000, 2009, Oracle. All rights reserved.
  • Welcome to DGMGRL, type "help" for information.
  • Connected.
  • DGMGRL> show configuration;

  • Configuration - DG_BROKER_CONFIG

  •   Protection Mode: MaxAvailability
  •   Databases:
  •     dg1 - Primary database
  •     dg2 - Physical standby database

  • Fast-Start Failover: DISABLED

  • Configuration Status:
  • SUCCESS

  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ WRITE           PRIMARY          dg1                  NO

  • SQL> shutdown abort
  • ORACLE instance shut down.
  

  2:在备库dg2上执行failover过程,failover执行的命令和switchover类似,只是在这个过程中,主库已经不可用
  


  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ ONLY WITH APPLY PHYSICAL STANDBY dg2                  NO

  • SQL> alter database recover managed standby database cancel;
  • Database altered.

  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ ONLY            PHYSICAL STANDBY dg2                  NO

  • 出现这个错误说明日志并未完全的应用
  • SQL> alter database commit to switchover to primary;
  • alter database commit to switchover to primary
  • *
  • ERROR at line 1:
  • ORA-16139: media recovery required

  • SQL> alter database recover managed standby database using current logfile disconnect from session;
  • Database altered.

  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ ONLY WITH APPLY PHYSICAL STANDBY dg2                  NO

  • SQL> alter database recover managed standby database finish;
  • Database altered.

  • SQL> alter database commit to switchover to primary;
  • Database altered.

  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • MOUNTED              PRIMARY          dg2                  NO

  • SQL> alter database open;
  • Database altered.

  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ WRITE           PRIMARY          dg2                  NO
  

  二:使用datagurad broker进行failover
  
1:开启主库和备库的闪回功能,主要用于主库恢复后的reinstate操作,当前主库为dg2,备库为dg1
  


  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ WRITE           PRIMARY          dg2                  YES

  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ ONLY WITH APPLY PHYSICAL STANDBY dg1                  YES

  • [oracle@dg1 ~]$ dgmgrl sys/123456@dg1
  • DGMGRL for Linux: Version 11.2.0.3.0 - 64bit Production

  • Copyright (c) 2000, 2009, Oracle. All rights reserved.

  • Welcome to DGMGRL, type "help" for information.
  • Connected.
  • DGMGRL> show configuration;

  • Configuration - DG_BROKER_CONFIG

  •   Protection Mode: MaxAvailability
  •   Databases:
  •     dg2 - Primary database
  •     dg1 - Physical standby database

  • Fast-Start Failover: DISABLED

  • Configuration Status:
  • SUCCESS
  

  2:关闭主库dg2,模拟主库故障
  


  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ WRITE           PRIMARY          dg2                  YES

  • SQL> shutdown abort
  • ORACLE instance shut down.

  • DGMGRL> show configuration;

  • Configuration - DG_BROKER_CONFIG

  •   Protection Mode: MaxAvailability
  •   Databases:
  •     dg2 - Primary database
  •     dg1 - Physical standby database

  • Fast-Start Failover: DISABLED

  • Configuration Status:
  • ORA-01034: ORACLE not available
  • ORA-16625: cannot reach database "dg2"
  • DGM-17017: unable to determine configuration status
  

  3:执行failover
  


  • DGMGRL> failover to dg1;
  • Performing failover NOW, please wait...
  • Failover succeeded, new primary is "dg1"
  • DGMGRL> show configuration;

  • Configuration - DG_BROKER_CONFIG

  •   Protection Mode: MaxAvailability
  •   Databases:
  •     dg1 - Primary database
  •       Warning: ORA-16629: database reports a different protection level from the protection mode

  •     dg2 - Physical standby database (disabled)
  •       ORA-16661: the standby database needs to be reinstated

  • Fast-Start Failover: DISABLED

  • Configuration Status:
  • WARNING
  

  4:重新启动原主库dg2
  


  • SQL> startup
  • ORACLE instance started.

  • Total System Global Area  417546240 bytes
  • Fixed Size                  2228944 bytes
  • Variable Size             352324912 bytes
  • Database Buffers           54525952 bytes
  • Redo Buffers                8466432 bytes
  • Database mounted.
  • ORA-16649: possible failover to another database prevents this database from
  • being opened

  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • MOUNTED              PRIMARY          dg2                  YES
  

  5:执行reinstate操作
  


  • DGMGRL> reinstate database dg2;
  • Reinstating database "dg2", please wait...
  • Operation requires shutdown of instance "dg" on database "dg2"
  • Shutting down instance "dg"...
  • ORA-01109: database not open

  • Database dismounted.
  • ORACLE instance shut down.
  • Operation requires startup of instance "dg" on database "dg2"
  • Starting instance "dg"...
  • Unable to connect to database
  • ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

  • Failed.
  • Warning: You are no longer connected to ORACLE.

  • Please complete the following steps and reissue the REINSTATE command:
  •         start up and mount instance "dg" of database "dg2"

  • SQL> conn /as sysdba
  • Connected to an idle instance.
  • SQL> startup
  • ORACLE instance started.

  • Total System Global Area  417546240 bytes
  • Fixed Size                  2228944 bytes
  • Variable Size             352324912 bytes
  • Database Buffers           54525952 bytes
  • Redo Buffers                8466432 bytes
  • Database mounted.
  • Database opened.
  • SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;

  • OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON
  • -------------------- ---------------- -------------------- ------------------
  • READ ONLY            PHYSICAL STANDBY dg2                  YES

  • DGMGRL> show configuration;

  • Configuration - DG_BROKER_CONFIG

  •   Protection Mode: MaxAvailability
  •   Databases:
  •     dg1 - Primary database
  •     dg2 - Physical standby database (disabled)
  •       ORA-16661: the standby database needs to be reinstated

  • Fast-Start Failover: DISABLED

  • Configuration Status:
  • SUCCESS

  • DGMGRL> enable database dg2;
  • Error: ORA-16661: the standby database needs to be reinstated

  • Failed.
  • DGMGRL> reinstate database dg2;
  • Reinstating database "dg2", please wait...
  • Reinstatement of database "dg2" succeeded

  • DGMGRL> show configuration;

  • Configuration - DG_BROKER_CONFIG

  •   Protection Mode: MaxAvailability
  •   Databases:
  •     dg1 - Primary database
  •     dg2 - Physical standby database

  • Fast-Start Failover: DISABLED

  • Configuration Status:
  • SUCCESS
  

  总结
  
1:非到万不得已的情况,不使用failover,优先考虑switchover
  
2:若执行failover,则考虑使用sql命令完成
  
3:执行failover后,应及时备份数据,并重构dg环境



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-599702-1-1.html 上篇帖子: oracle exists and not exist 下篇帖子: ORACLE ASM初试
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表