Data Guard Broker配置与主备库切换指南

简介:

Data Guard Broker基于分布式的管理框架,可以用来集中创建,管理,配置和监控oracle data guard; Data Guard Broker的组件:
客户端:Oracle grid control和命令行工具DGMGRL
服务端:DMON进程和配置文件
DMON进程的作用: 响应用户的请求,更新broker的配置文件,和data guard配置中的其他服务器通信

Data Guard Broker配置要求:
数据库版本为:企业版10G R1以上,可以是单实例或者rac环境;
在主库和备库上的COMPATIBLE参数必须设定为9.2.0或更高;
必须有oracle网络支持,必须配置LOCAL_LISTENER静态监听器注册(非1521端口必须);
GLOBAL_DBNAME属性必须设定为db_uniquename_DGMGRL.db_domain;
DG_BROKER_START参数要设置为TRUE;
主库必须运行在归档模式;
使用spfile来保证broker的配置文件和服务器初始化参数文件的一致;
所有的数据库必须在mount(物理备库)或者open(主库和逻辑备库)状态;
在rac环境下还需要配置DB_BROKER_CONFIG_FILEn参数,将该参数指定共享存储上;
rac环境下,需要在OCR中要设定start_options参数为mount;

srvctl add database -d <db_unique_name> -o <ORACLE_HOME> -s mount
或者
srvctl modify database -d <db_unique_name> -o <ORACLE_HOME> -s mount

data guard broker体系结构示意图:

配置Data Guard Broker,开始之前应该配置好data guard,并保证日志同步和应用正常

1:配置listener.ora文件和tnsnames.ora文件,添加GLOBAL_DBNAME参数,重启监听器,所有的节点都需要配置

 
  1. [oracle@orcl ~]$ cat $ORACLE_HOME/network/admin/listener.ora  
  2. SID_LIST_LISTENER =  
  3.   (SID_LIST =  
  4.     (SID_DESC =  
  5.       (SID_NAME = PLSExtProc)  
  6.       (GLOBAL_DBNAME = physical_DGMGRL.herostart.com)  
  7.       (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)  
  8.       (PROGRAM = extproc)  
  9.     )  
  10.   )  
  11.  
  12. LISTENER =  
  13.   (DESCRIPTION_LIST =  
  14.     (DESCRIPTION =  
  15.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.227.30)(PORT = 1521))  
  16.       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))  
  17.     )  
  18.   )  
  19.  
  20. [oracle@orcl ~]$ lsnrctl services |grep DGMGRL  
  21. Service "physical_DGMGRL.herostart.com" has 1 instance(s).  
  22.  
  23. [oracle@physical ~]$ cat $ORACLE_HOME/network/admin/tnsnames.ora  
  24. PRIMARY =  
  25.   (DESCRIPTION =  
  26.     (ADDRESS_LIST =  
  27.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.227.20)(PORT = 1521))  
  28.     )  
  29.     (CONNECT_DATA =  
  30.       (SERVICE_NAME = primary.herostart.com)  
  31.     )  
  32.   )  
  33.  
  34. PHYSICAL =  
  35.   (DESCRIPTION =  
  36.     (ADDRESS_LIST =  
  37.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.227.30)(PORT = 1521))  
  38.     )  
  39.     (CONNECT_DATA =  
  40.       (SERVICE_NAME = physical.herostart.com)  
  41.     )  
  42.   ) 

2:设置DG_BROKER_START参数,所有的节点都需要配置

 
  1. SQL> show parameter dg_broker_start;  
  2.  
  3. NAME                                 TYPE        VALUE  
  4. ------------------------------------ ----------- ------------------------------  
  5. dg_broker_start                      boolean     FALSE  
  6. SQL> !ps -ef |grep dmon  
  7. oracle   17111 17094  0 15:59 pts/2    00:00:00 /bin/bash -c ps -ef |grep dmon  
  8. oracle   17113 17111  0 15:59 pts/2    00:00:00 grep dmon  
  9.  
  10. SQL> alter system set dg_broker_start=TRUE;  
  11. System altered.  
  12.  
  13. SQL> !ps -ef |grep dmon  
  14. oracle   17128     1  0 15:59 ?        00:00:00 ora_dmon_orcl  
  15. oracle   17129 17094  0 15:59 pts/2    00:00:00 /bin/bash -c ps -ef |grep dmon 

3:创建并启用配置文件

 
  1. [oracle@primary dbs]$ dgmgrl sys/123456@primary  
  2. DGMGRL for Linux: Version 10.2.0.1.0 - Production  
  3. Copyright (c) 2000, 2005, Oracle. All rights reserved.  
  4. Welcome to DGMGRL, type "help" for information.  
  5. Connected.  
  6. DGMGRL> show configuration;  
  7. Error: ORA-16532: Data Guard broker configuration does not exist  
  8.  
  9. Configuration details cannot be determined by DGMGRL  
  10. DGMGRL> create configuration 'DG_YANG' as primary database   is 'primary' connect identifier is primary;  
  11. Configuration "DG_YANG" created with primary database "primary"  
  12. DGMGRL> show database verbose primary;  
  13.  
  14. Database  
  15.   Name:            primary  
  16.   Role:            PRIMARY  
  17.   Enabled:         NO  
  18.   Intended State:  OFFLINE  
  19.   Instance(s):  
  20.     orcl  
  21.  
  22.   Properties:  
  23.     InitialConnectIdentifier        = 'primary' 
  24.     LogXptMode                      = 'ASYNC' 
  25.     Dependency                      = '' 
  26.     DelayMins                       = '0' 
  27.     Binding                         = 'OPTIONAL' 
  28.     MaxFailure                      = '0' 
  29.     MaxConnections                  = '1' 
  30.     ReopenSecs                      = '300' 
  31.     NetTimeout                      = '180' 
  32.     LogShipping                     = 'ON' 
  33.     PreferredApplyInstance          = '' 
  34.     ApplyInstanceTimeout            = '0' 
  35.     ArchiveLagTarget                = '0' 
  36.     LogArchiveMaxProcesses          = '2' 
  37.     LogArchiveMinSucceedDest        = '1' 
  38.     FastStartFailoverTarget         = '' 
  39.     StatusReport                    = '(monitor)' 
  40.     InconsistentProperties          = '(monitor)' 
  41.     InconsistentLogXptProps         = '(monitor)' 
  42.     SendQEntries                    = '(monitor)' 
  43.     LogXptStatus                    = '(monitor)' 
  44.     RecvQEntries                    = '(monitor)' 
  45.     HostName                        = 'primary.herostart.com' 
  46.     SidName                         = 'orcl' 
  47.     LocalListenerAddress            = '(ADDRESS=(PROTOCOL=tcp)(HOST=primary.herostart.com)(PORT=1521))' 
  48.     StandbyArchiveLocation          = 'dgsby_primary' 
  49.     AlternateLocation               = '' 
  50.     LogArchiveTrace                 = '0' 
  51.     LogArchiveFormat                = '%t_%s_%r.dbf' 
  52.     LatestLog                       = '(monitor)' 
  53.     TopWaitEvents                   = '(monitor)' 
  54.  
  55. Current status for "primary":  
  56. DISABLED  
  57.  
  58. DGMGRL>  add database 'physical' as connect identifier is physical  maintained as physical;  
  59. Database "physical" added  
  60. DGMGRL> show database verbose physical;  
  61.  
  62. Database  
  63.   Name:            physical  
  64.   Role:            PHYSICAL STANDBY  
  65.   Enabled:         NO  
  66.   Intended State:  OFFLINE  
  67.   Instance(s):  
  68.     orcl  
  69.  
  70.   Properties:  
  71.     InitialConnectIdentifier        = 'physical' 
  72.     LogXptMode                      = 'ARCH' 
  73.     Dependency                      = '' 
  74.     DelayMins                       = '0' 
  75.     Binding                         = 'OPTIONAL' 
  76.     MaxFailure                      = '0' 
  77.     MaxConnections                  = '1' 
  78.     ReopenSecs                      = '300' 
  79.     NetTimeout                      = '180' 
  80.     LogShipping                     = 'ON' 
  81.     PreferredApplyInstance          = '' 
  82.     ApplyInstanceTimeout            = '0' 
  83.     ApplyParallel                   = 'AUTO' 
  84.     StandbyFileManagement           = 'AUTO' 
  85.     ArchiveLagTarget                = '0' 
  86.     LogArchiveMaxProcesses          = '2' 
  87.     LogArchiveMinSucceedDest        = '1' 
  88.     DbFileNameConvert               = '' 
  89.     LogFileNameConvert              = '' 
  90.     FastStartFailoverTarget         = '' 
  91.     StatusReport                    = '(monitor)' 
  92.     InconsistentProperties          = '(monitor)' 
  93.     InconsistentLogXptProps         = '(monitor)' 
  94.     SendQEntries                    = '(monitor)' 
  95.     LogXptStatus                    = '(monitor)' 
  96.     RecvQEntries                    = '(monitor)' 
  97.     HostName                        = 'physical.herostart.com' 
  98.     SidName                         = 'orcl' 
  99.     LocalListenerAddress            = '(ADDRESS=(PROTOCOL=tcp)(HOST=physical.herostart.com)(PORT=1521))' 
  100.     StandbyArchiveLocation          = '/u01/arch/physical_logs/' 
  101.     AlternateLocation               = '' 
  102.     LogArchiveTrace                 = '0' 
  103.     LogArchiveFormat                = '%t_%s_%r.dbf' 
  104.     LatestLog                       = '(monitor)' 
  105.     TopWaitEvents                   = '(monitor)' 
  106.  
  107. Current status for "physical":  
  108. DISABLED  
  109. DGMGRL> enable configuration;  
  110. Enabled. 

备注:在enbale configration这步有个小插曲,出现了“Failed to connect to remote database primary. Error is ORA-12514”错误!
详细内容请参考:
http://www.itpub.net/thread-1500089-1-1.html

 
  1.  
  2. enable过程需要点时间,可以在备库上查看日志:  
  3. [oracle@physical ~]$ tail -f /u01/app/oracle/admin/orcl/bdump/drcorcl.log   
  4.  
  5. DGMGRL> show configuration;  
  6.  
  7. Configuration  
  8.   Name:                DG_YANG  
  9.   Enabled:             YES  
  10.   Protection Mode:     MaxPerformance  
  11.   Fast-Start Failover: DISABLED  
  12.   Databases:  
  13.     primary  - Primary database  
  14.     physical - Physical standby database  
  15.  
  16. Current status for "DG_YANG":  
  17. SUCCESS 

更详细的资料请参考:http://download.oracle.com/docs/cd/B12037_01/server.101/b10822/cli.htm

4:主备库切换

 
  1. SQL> select name,open_mode,database_role,switchover_status from v$database;  
  2.  
  3. NAME      OPEN_MODE  DATABASE_ROLE    SWITCHOVER_STATUS  
  4. --------- ---------- ---------------- --------------------  
  5. ORCL      READ WRITE PRIMARY          SESSIONS ACTIVE  
  6.  
  7.  
  8. SQL> select name,open_mode,database_role,switchover_status from v$database;  
  9.  
  10. NAME      OPEN_MODE  DATABASE_ROLE    SWITCHOVER_STATUS  
  11. --------- ---------- ---------------- --------------------  
  12. ORCL      MOUNTED    PHYSICAL STANDBY NOT ALLOWED  
  13.  
  14. 开始切换,中间会提示连接不到数据库,不知道11g版本会不会这样  
  15. DGMGRL> switchover to physical;  
  16. Performing switchover NOW, please wait...  
  17. Operation requires shutdown of instance "orcl" on database "primary"  
  18. Shutting down instance "orcl"...  
  19. ORA-01109: database not open  
  20.  
  21. Database dismounted.  
  22. ORACLE instance shut down.  
  23. Operation requires shutdown of instance "orcl" on database "physical"  
  24. Shutting down instance "orcl"...  
  25. ORA-01109: database not open  
  26.  
  27. Database dismounted.  
  28. ORACLE instance shut down.  
  29. Operation requires startup of instance "orcl" on database "primary"  
  30. Starting instance "orcl"...  
  31. Unable to connect to database  
  32. ORA-12521: TNS:listener does not currently know of instance requested in connect descriptor Failed.  
  33. You are no longer connected to ORACLE  
  34. Please connect again.  
  35. Unable to start instance "orcl"  
  36. You must start instance "orcl" manually  
  37. Operation requires startup of instance "orcl" on database "physical"  
  38. You must start instance "orcl" manually  
  39. Switchover succeeded, new primary is "physical"  
  40.  
  41. [oracle@primary dbs]$ sqlplus /nolog  
  42. SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 13 14:36:08 2011  
  43. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
  44. SQL> conn /as sysdba  
  45. Connected to an idle instance.  
  46. SQL> startup mount  
  47. ORACLE instance started.  
  48.  
  49. Total System Global Area  167772160 bytes  
  50. Fixed Size                  1218316 bytes  
  51. Variable Size              71305460 bytes  
  52. Database Buffers           92274688 bytes  
  53. Redo Buffers                2973696 bytes  
  54. Database mounted.  
  55. SQL> alter database recover managed standby database disconnect from session;  
  56. Database altered.  
  57.  
  58. SQL> select open_mode,name,database_role,switchover_status from v$database;  
  59.  
  60. OPEN_MODE  NAME      DATABASE_ROLE    SWITCHOVER_STATUS  
  61. ---------- --------- ---------------- --------------------  
  62. MOUNTED    ORCL      PHYSICAL STANDBY NOT ALLOWED  
  63.  
  64.  
  65.  
  66. [oracle@physical ~]$ sqlplus /nolog  
  67. SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 13 14:37:06 2011  
  68. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
  69. SQL> conn /as sysdba  
  70. Connected to an idle instance.  
  71. SQL> startup  
  72. ORACLE instance started.  
  73.  
  74. Total System Global Area  167772160 bytes  
  75. Fixed Size                  1218316 bytes  
  76. Variable Size              62916852 bytes  
  77. Database Buffers          100663296 bytes  
  78. Redo Buffers                2973696 bytes  
  79. Database mounted.  
  80. Database opened.  
  81. SQL> select open_mode,name,database_role,switchover_status from v$database;  
  82.  
  83. OPEN_MODE  NAME      DATABASE_ROLE    SWITCHOVER_STATUS  
  84. ---------- --------- ---------------- --------------------  
  85. READ WRITE ORCL      PRIMARY          SESSIONS ACTIVE  
  86.  
  87.  
  88. SQL> archive log list;  
  89. Database log mode              Archive Mode  
  90. Automatic archival             Enabled  
  91. Archive destination            /u01/arch/physical_logs/  
  92. Oldest online log sequence     15  
  93. Next log sequence to archive   16  
  94. Current log sequence           16  
  95. SQL> alter system switch logfile;  
  96. System altered.  
  97.  
  98. SQL> archive log list;  
  99. Database log mode              Archive Mode  
  100. Automatic archival             Enabled  
  101. Archive destination            /u01/arch/physical_logs/  
  102. Oldest online log sequence     15  
  103. Next log sequence to archive   17  
  104. Current log sequence           17  
  105.  
  106.  
  107. 备库:  
  108. SQL> select first_time,next_time,sequence#,applied from v$archived_log where sequence# >= 15;  
  109.  
  110. FIRST_TIME          NEXT_TIME            SEQUENCE# APP  
  111. ------------------- ------------------- ---------- ---  
  112. 2011-10-13:14:33:14 2011-10-13:14:38:16         15 YES  
  113. 2011-10-13:14:38:16 2011-10-13:14:42:38         16 YES 

5:DGMGRL报错如下

 
  1. [oracle@physical u01]$ dgmgrl sys/123456@physical  
  2. DGMGRL for Linux: Version 10.2.0.1.0 - Production  
  3. Copyright (c) 2000, 2005, Oracle. All rights reserved.  
  4. Welcome to DGMGRL, type "help" for information.  
  5. Connected.  
  6. DGMGRL> show configuration;  
  7.  
  8. Configuration  
  9.   Name:                DG_YANG  
  10.   Enabled:             YES  
  11.   Protection Mode:     MaxPerformance  
  12.   Fast-Start Failover: DISABLED  
  13.   Databases:  
  14.     primary  - Physical standby database  
  15.     physical - Primary database  
  16.  
  17. Current status for "DG_YANG":  
  18. Warning: ORA-16608: one or more databases have warnings  
  19.  
  20. DGMGRL> show database physical statusreport;  
  21. STATUS REPORT  
  22.        INSTANCE_NAME   SEVERITY ERROR_TEXT  
  23.  
  24. DGMGRL> show database primary statusreport;  
  25. STATUS REPORT  
  26.        INSTANCE_NAME   SEVERITY ERROR_TEXT  
  27.                    *    WARNING ORA-16826: apply service state is inconsistent with the DelayMins property  
  28.                      
  29. 原因:  
  30. Oracle Error :: ORA-16826 apply service state is inconsistent with the DelayMins property  
  31.  
  32. Cause  
  33. This warning was caused by one of the following reasons:  
  34. - The apply service was started without specifying the real-time apply option or without the NODELAY option when the DelayMins property was set to zero.  
  35.  
  36. - The apply service was started with the real-time apply option or with the NODELAY option when the DelayMins property was set to a value greater than zero.  
  37.  
  38. Action  
  39. Reenable the standby database to allow the broker to restart the apply service with the apply options that are consistent with the specified value of the DelayMins property.  
  40.  
  41.  
  42. DGMGRL> show database primary DelayMins;  
  43.   DelayMins = '0' 
  44. DGMGRL> edit database primary set property DelayMins=1;  
  45. Property "delaymins" updated          
  46.  
  47. DGMGRL> edit database physical set property DelayMins=1;  
  48. Property "delaymins" updated  
  49.  
  50. DGMGRL> show configuration;  
  51.  
  52. Configuration  
  53.   Name:                DG_YANG  
  54.   Enabled:             YES  
  55.   Protection Mode:     MaxPerformance  
  56.   Fast-Start Failover: DISABLED  
  57.   Databases:  
  58.     primary  - Physical standby database  
  59.     physical - Primary database  
  60.  
  61. Current status for "DG_YANG":  
  62. SUCCESS  
  63.  
  64. DGMGRL> show database primary statusreport;  
  65. STATUS REPORT  
  66.        INSTANCE_NAME   SEVERITY ERROR_TEXT         

 2011年11月2日更新,之前提到在switchover中间会提示连不上数据库,经过排查,发现是tnsnames.ora文件service_name配置不正确导致,参考文档:

https://forums.oracle.com/forums/thread.jspa?threadID=307281

 本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/686900如需转载请自行联系原作者


ylw6006

相关文章
|
弹性计算 网络协议 容灾
PostgreSQL 时间点恢复(PITR)在异步流复制主从模式下,如何避免主备切换后PITR恢复(备库、容灾节点、只读节点)走错时间线(timeline , history , partial , restore_command , recovery.conf)
标签 PostgreSQL , 恢复 , 时间点恢复 , PITR , restore_command , recovery.conf , partial , history , 任意时间点恢复 , timeline , 时间线 背景 政治正确非常重要,对于数据库来说亦如此,一个基于流复制的HA架构的集群,如果还有一堆只读节点,当HA集群发生了主备切换后,这些只读节点能否与新的主节点保持
1656 0
|
6月前
|
NoSQL Redis 容器
Redis集群报错cluster_state:fail,如何解决并重新恢复集群(IP问题/ slot未完全分配问题)
Redis集群报错cluster_state:fail,如何解决并重新恢复集群(IP问题/ slot未完全分配问题)
107 0
|
NoSQL API Redis
Undermoon - 为 Memory Broker 设置备份
Undermoon - 为 Memory Broker 设置备份
115 0
|
关系型数据库 网络安全 数据库
PGPool-II+PG流复制实现HA主备切换
基于PG的流复制能实现热备切换,但是是要手动建立触发文件实现,对于一些HA场景来说,需要当主机down了后,备机自动切换,经查询资料知道pgpool-II可以实现这种功能。
2892 0
|
SQL 监控 关系型数据库
Data Guard高级玩法:通过闪回恢复failover备库
    今天看到有一个网友提了一个问题,描述很简短     测试DG时,主库不能宕机,如何测试failover?     其实这个需求从业务层面来说是合理的,一个数据量很大的核心数据库,如果需要做灾难演练,就希望在备库上做一下演练工作,而这个演练其实又不想影响到目前的主库,而且又希望能够尽可能模拟真实的情况,我想这样对于运维部门来说是最具有考核力度,而对于开发业务部门来说是最受欢迎的,因为他们什么都不需要改动。
1086 0
|
Oracle 关系型数据库 Linux
12c Data Guard Broker 配置
12c Data Guard Broker 配置,18c Data Guard Broker 配置
1822 0
|
Oracle 关系型数据库 数据库