博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle Datagurad Failover
阅读量:7059 次
发布时间:2019-06-28

本文共 7610 字,大约阅读时间需要 25 分钟。

生产环境中,可能会有各种各样的原因导致数据库不能提供服务,例如数据库库的硬件故障,操作系统故障或软件bug,人为的失误(例如rm -rf /)等,在这种情况下,dataguard显得尤为重要,当主库不可用的时候,可以将备库failover成主库继续提供服务,failover和switchover不同的是,执行failover后,原有的dataguard配置将会失效且有可能会丢失部分数据,所以在生产环境中能用switchover解决的问题则应尽量采用switchover!

一:使用sql命令执行failover

1:查看当前的主库是dg1,物理备库为dg2,将主库关闭,模拟主库故障

 
  1. [oracle@dg2 ~]$ dgmgrl /  

  2. DGMGRL for Linux: Version 11.2.0.3.0 - 64bit Production  

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

  4. Welcome to DGMGRL, type "help" for information.  

  5. Connected.  

  6. DGMGRL> show configuration;  

  7. Configuration - DG_BROKER_CONFIG  

  8.   Protection Mode: MaxAvailability  

  9.   Databases:  

  10.     dg1 - Primary database  

  11.     dg2 - Physical standby database  

  12. Fast-Start Failover: DISABLED  

  13. Configuration Status:  

  14. SUCCESS  

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

  16. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  17. -------------------- ---------------- -------------------- ------------------  

  18. READ WRITE           PRIMARY          dg1                  NO  

  19. SQL> shutdown abort  

  20. ORACLE instance shut down. 

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

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

  2. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  3. -------------------- ---------------- -------------------- ------------------  

  4. READ ONLY WITH APPLY PHYSICAL STANDBY dg2                  NO  

  5. SQL> alter database recover managed standby database cancel;  

  6. Database altered.  

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

  8. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  9. -------------------- ---------------- -------------------- ------------------  

  10. READ ONLY            PHYSICAL STANDBY dg2                  NO  

  11. 出现这个错误说明日志并未完全的应用

  12. SQL> alter database commit to switchover to primary;  

  13. alter database commit to switchover to primary  

  14. *  

  15. ERROR at line 1:  

  16. ORA-16139: media recovery required  

  17. SQL> alter database recover managed standby database using current logfile disconnect from session;  

  18. Database altered.  

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

  20. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  21. -------------------- ---------------- -------------------- ------------------  

  22. READ ONLY WITH APPLY PHYSICAL STANDBY dg2                  NO  

  23. SQL> alter database recover managed standby database finish;  

  24. Database altered.  

  25. SQL> alter database commit to switchover to primary;  

  26. Database altered.  

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

  28. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  29. -------------------- ---------------- -------------------- ------------------  

  30. MOUNTED              PRIMARY          dg2                  NO  

  31. SQL> alter database open;  

  32. Database altered.  

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

  34. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  35. -------------------- ---------------- -------------------- ------------------  

  36. READ WRITE           PRIMARY          dg2                  NO 

二:使用datagurad broker进行failover

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

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

  2. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  3. -------------------- ---------------- -------------------- ------------------  

  4. READ WRITE           PRIMARY          dg2                  YES  

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

  6. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  7. -------------------- ---------------- -------------------- ------------------  

  8. READ ONLY WITH APPLY PHYSICAL STANDBY dg1                  YES  

  9. [oracle@dg1 ~]$ dgmgrl sys/123456@dg1  

  10. DGMGRL for Linux: Version 11.2.0.3.0 - 64bit Production  

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

  12. Welcome to DGMGRL, type "help" for information.  

  13. Connected.  

  14. DGMGRL> show configuration;  

  15. Configuration - DG_BROKER_CONFIG  

  16.   Protection Mode: MaxAvailability  

  17.   Databases:  

  18.     dg2 - Primary database  

  19.     dg1 - Physical standby database  

  20. Fast-Start Failover: DISABLED  

  21. Configuration Status:  

  22. SUCCESS 

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

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

  2. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  3. -------------------- ---------------- -------------------- ------------------  

  4. READ WRITE           PRIMARY          dg2                  YES  

  5. SQL> shutdown abort  

  6. ORACLE instance shut down.  

  7. DGMGRL> show configuration;  

  8. Configuration - DG_BROKER_CONFIG  

  9.   Protection Mode: MaxAvailability  

  10.   Databases:  

  11.     dg2 - Primary database  

  12.     dg1 - Physical standby database  

  13. Fast-Start Failover: DISABLED  

  14. Configuration Status:  

  15. ORA-01034: ORACLE not available  

  16. ORA-16625: cannot reach database "dg2"  

  17. DGM-17017: unable to determine configuration status 

3:执行failover

 
  1. DGMGRL> failover to dg1;  

  2. Performing failover NOW, please wait...  

  3. Failover succeeded, new primary is "dg1"  

  4. DGMGRL> show configuration;  

  5. Configuration - DG_BROKER_CONFIG  

  6.   Protection Mode: MaxAvailability  

  7.   Databases:  

  8.     dg1 - Primary database  

  9.       Warning: ORA-16629: database reports a different protection level from the protection mode  

  10.     dg2 - Physical standby database (disabled)  

  11.       ORA-16661: the standby database needs to be reinstated  

  12. Fast-Start Failover: DISABLED  

  13. Configuration Status:  

  14. WARNING 

4:重新启动原主库dg2

 
  1. SQL> startup  

  2. ORACLE instance started.  

  3. Total System Global Area  417546240 bytes  

  4. Fixed Size                  2228944 bytes  

  5. Variable Size             352324912 bytes  

  6. Database Buffers           54525952 bytes  

  7. Redo Buffers                8466432 bytes  

  8. Database mounted.  

  9. ORA-16649: possible failover to another database prevents this database from  

  10. being opened  

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

  12. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  13. -------------------- ---------------- -------------------- ------------------  

  14. MOUNTED              PRIMARY          dg2                  YES 

5:执行reinstate操作

 
  1. DGMGRL> reinstate database dg2;  

  2. Reinstating database "dg2", please wait...  

  3. Operation requires shutdown of instance "dg" on database "dg2"  

  4. Shutting down instance "dg"...  

  5. ORA-01109: database not open  

  6. Database dismounted.  

  7. ORACLE instance shut down.  

  8. Operation requires startup of instance "dg" on database "dg2"  

  9. Starting instance "dg"...  

  10. Unable to connect to database  

  11. ORA-12514: TNS:listener does not currently know of service requested in connect descriptor  

  12. Failed.  

  13. Warning: You are no longer connected to ORACLE.  

  14. Please complete the following steps and reissue the REINSTATE command:  

  15.         start up and mount instance "dg" of database "dg2"  

  16. SQL> conn /as sysdba  

  17. Connected to an idle instance.  

  18. SQL> startup  

  19. ORACLE instance started.  

  20. Total System Global Area  417546240 bytes  

  21. Fixed Size                  2228944 bytes  

  22. Variable Size             352324912 bytes  

  23. Database Buffers           54525952 bytes  

  24. Redo Buffers                8466432 bytes  

  25. Database mounted.  

  26. Database opened.  

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

  28. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

  29. -------------------- ---------------- -------------------- ------------------  

  30. READ ONLY            PHYSICAL STANDBY dg2                  YES  

  31. DGMGRL> show configuration;  

  32. Configuration - DG_BROKER_CONFIG  

  33.   Protection Mode: MaxAvailability  

  34.   Databases:  

  35.     dg1 - Primary database  

  36.     dg2 - Physical standby database (disabled)  

  37.       ORA-16661: the standby database needs to be reinstated  

  38. Fast-Start Failover: DISABLED  

  39. Configuration Status:  

  40. SUCCESS  

  41. DGMGRL> enable database dg2;  

  42. Error: ORA-16661: the standby database needs to be reinstated  

  43. Failed.  

  44. DGMGRL> reinstate database dg2;  

  45. Reinstating database "dg2", please wait...  

  46. Reinstatement of database "dg2" succeeded  

  47. DGMGRL> show configuration;  

  48. Configuration - DG_BROKER_CONFIG  

  49.   Protection Mode: MaxAvailability  

  50.   Databases:  

  51.     dg1 - Primary database  

  52.     dg2 - Physical standby database  

  53. Fast-Start Failover: DISABLED  

  54. Configuration Status:  

  55. SUCCESS 

总结

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

本文转自东方之子736651CTO博客,原文链接: http://blog.51cto.com/ecloud/1381881,如需转载请自行联系原作者

你可能感兴趣的文章
让手机支持OTG,不看绝对后悔! - 我也做一回搬运工,解决RFID读卡器OTG支持问题...
查看>>
Hadoop-2.7.0 HDFS DataXceiverServer两个参数的疑问
查看>>
linux exec函数家族
查看>>
几种软负载均衡策略分析
查看>>
.net——序列化与反序列化中对日期时间的处理
查看>>
独家揭露网站内链建设seo优化的科学方法
查看>>
MVVM 模式介绍
查看>>
.NET Core采用的全新配置系统[10]: 配置的同步机制是如何实现的?
查看>>
阿里云AI首席科学家闵万里:让萧山救护车等待时间至少降低50%,“城市大脑”是如何做到的...
查看>>
《Linux From Scratch》第二部分:准备构建 第四章:最后的准备- 4.2. 创建 $LFS/tools 文件夹...
查看>>
再谈数据外泄和数据库安全
查看>>
Java 程序优化:字符串操作、基本运算方法等优化策略
查看>>
[ASP.NET MVC]通过对HtmlHelper扩展简化“列表控件”的绑定
查看>>
[译] 关于 React Router 4 的一切
查看>>
vivo联手火星情报局打造最强粉丝嘉年华:超级装备X20惊艳全场
查看>>
本田推出电动车和多功能移动机器人,2019年上市
查看>>
将DJANGO管理界面的filter_horizontal移到前面来复用
查看>>
因不公平竞争,高通在台被处以51亿罚款
查看>>
算法精解:最小二乘法C实现
查看>>
一文让你迅速读懂Serverless
查看>>