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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章