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參數,重啓監聽器,所有的節點都需要配置
- [oracle@orcl ~]$ cat $ORACLE_HOME/network/admin/listener.ora
- SID_LIST_LISTENER =
- (SID_LIST =
- (SID_DESC =
- (SID_NAME = PLSExtProc)
- (GLOBAL_DBNAME = physical_DGMGRL.herostart.com)
- (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
- (PROGRAM = extproc)
- )
- )
- LISTENER =
- (DESCRIPTION_LIST =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.227.30)(PORT = 1521))
- (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
- )
- )
- [oracle@orcl ~]$ lsnrctl services |grep DGMGRL
- Service "physical_DGMGRL.herostart.com" has 1 instance(s).
- [oracle@physical ~]$ cat $ORACLE_HOME/network/admin/tnsnames.ora
- PRIMARY =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.227.20)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = primary.herostart.com)
- )
- )
- PHYSICAL =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.227.30)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = physical.herostart.com)
- )
- )
2:設置DG_BROKER_START參數,所有的節點都需要配置
- SQL> show parameter dg_broker_start;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- dg_broker_start boolean FALSE
- SQL> !ps -ef |grep dmon
- oracle 17111 17094 0 15:59 pts/2 00:00:00 /bin/bash -c ps -ef |grep dmon
- oracle 17113 17111 0 15:59 pts/2 00:00:00 grep dmon
- SQL> alter system set dg_broker_start=TRUE;
- System altered.
- SQL> !ps -ef |grep dmon
- oracle 17128 1 0 15:59 ? 00:00:00 ora_dmon_orcl
- oracle 17129 17094 0 15:59 pts/2 00:00:00 /bin/bash -c ps -ef |grep dmon
3:創建並啓用配置文件
- [oracle@primary dbs]$ dgmgrl sys/123456@primary
- DGMGRL for Linux: Version 10.2.0.1.0 - Production
- Copyright (c) 2000, 2005, Oracle. All rights reserved.
- Welcome to DGMGRL, type "help" for information.
- Connected.
- DGMGRL> show configuration;
- Error: ORA-16532: Data Guard broker configuration does not exist
- Configuration details cannot be determined by DGMGRL
- DGMGRL> create configuration 'DG_YANG' as primary database is 'primary' connect identifier is primary;
- Configuration "DG_YANG" created with primary database "primary"
- DGMGRL> show database verbose primary;
- Database
- Name: primary
- Role: PRIMARY
- Enabled: NO
- Intended State: OFFLINE
- Instance(s):
- orcl
- Properties:
- InitialConnectIdentifier = 'primary'
- LogXptMode = 'ASYNC'
- Dependency = ''
- DelayMins = '0'
- Binding = 'OPTIONAL'
- MaxFailure = '0'
- MaxConnections = '1'
- ReopenSecs = '300'
- NetTimeout = '180'
- LogShipping = 'ON'
- PreferredApplyInstance = ''
- ApplyInstanceTimeout = '0'
- ArchiveLagTarget = '0'
- LogArchiveMaxProcesses = '2'
- LogArchiveMinSucceedDest = '1'
- FastStartFailoverTarget = ''
- StatusReport = '(monitor)'
- InconsistentProperties = '(monitor)'
- InconsistentLogXptProps = '(monitor)'
- SendQEntries = '(monitor)'
- LogXptStatus = '(monitor)'
- RecvQEntries = '(monitor)'
- HostName = 'primary.herostart.com'
- SidName = 'orcl'
- LocalListenerAddress = '(ADDRESS=(PROTOCOL=tcp)(HOST=primary.herostart.com)(PORT=1521))'
- StandbyArchiveLocation = 'dgsby_primary'
- AlternateLocation = ''
- LogArchiveTrace = '0'
- LogArchiveFormat = '%t_%s_%r.dbf'
- LatestLog = '(monitor)'
- TopWaitEvents = '(monitor)'
- Current status for "primary":
- DISABLED
- DGMGRL> add database 'physical' as connect identifier is physical maintained as physical;
- Database "physical" added
- DGMGRL> show database verbose physical;
- Database
- Name: physical
- Role: PHYSICAL STANDBY
- Enabled: NO
- Intended State: OFFLINE
- Instance(s):
- orcl
- Properties:
- InitialConnectIdentifier = 'physical'
- LogXptMode = 'ARCH'
- Dependency = ''
- DelayMins = '0'
- Binding = 'OPTIONAL'
- MaxFailure = '0'
- MaxConnections = '1'
- ReopenSecs = '300'
- NetTimeout = '180'
- LogShipping = 'ON'
- PreferredApplyInstance = ''
- ApplyInstanceTimeout = '0'
- ApplyParallel = 'AUTO'
- StandbyFileManagement = 'AUTO'
- ArchiveLagTarget = '0'
- LogArchiveMaxProcesses = '2'
- LogArchiveMinSucceedDest = '1'
- DbFileNameConvert = ''
- LogFileNameConvert = ''
- FastStartFailoverTarget = ''
- StatusReport = '(monitor)'
- InconsistentProperties = '(monitor)'
- InconsistentLogXptProps = '(monitor)'
- SendQEntries = '(monitor)'
- LogXptStatus = '(monitor)'
- RecvQEntries = '(monitor)'
- HostName = 'physical.herostart.com'
- SidName = 'orcl'
- LocalListenerAddress = '(ADDRESS=(PROTOCOL=tcp)(HOST=physical.herostart.com)(PORT=1521))'
- StandbyArchiveLocation = '/u01/arch/physical_logs/'
- AlternateLocation = ''
- LogArchiveTrace = '0'
- LogArchiveFormat = '%t_%s_%r.dbf'
- LatestLog = '(monitor)'
- TopWaitEvents = '(monitor)'
- Current status for "physical":
- DISABLED
- DGMGRL> enable configuration;
- Enabled.
備註:在enbale configration這步有個小插曲,出現了“Failed to connect to remote database primary. Error is ORA-12514”錯誤!
詳細內容請參考:http://www.itpub.net/thread-1500089-1-1.html
- enable過程需要點時間,可以在備庫上查看日誌:
- [oracle@physical ~]$ tail -f /u01/app/oracle/admin/orcl/bdump/drcorcl.log
- DGMGRL> show configuration;
- Configuration
- Name: DG_YANG
- Enabled: YES
- Protection Mode: MaxPerformance
- Fast-Start Failover: DISABLED
- Databases:
- primary - Primary database
- physical - Physical standby database
- Current status for "DG_YANG":
- SUCCESS
更詳細的資料請參考:http://download.oracle.com/docs/cd/B12037_01/server.101/b10822/cli.htm
4:主備庫切換
- SQL> select name,open_mode,database_role,switchover_status from v$database;
- NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
- --------- ---------- ---------------- --------------------
- ORCL READ WRITE PRIMARY SESSIONS ACTIVE
- SQL> select name,open_mode,database_role,switchover_status from v$database;
- NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
- --------- ---------- ---------------- --------------------
- ORCL MOUNTED PHYSICAL STANDBY NOT ALLOWED
- 開始切換,中間會提示連接不到數據庫,不知道11g版本會不會這樣
- DGMGRL> switchover to physical;
- Performing switchover NOW, please wait...
- Operation requires shutdown of instance "orcl" on database "primary"
- Shutting down instance "orcl"...
- ORA-01109: database not open
- Database dismounted.
- ORACLE instance shut down.
- Operation requires shutdown of instance "orcl" on database "physical"
- Shutting down instance "orcl"...
- ORA-01109: database not open
- Database dismounted.
- ORACLE instance shut down.
- Operation requires startup of instance "orcl" on database "primary"
- Starting instance "orcl"...
- Unable to connect to database
- ORA-12521: TNS:listener does not currently know of instance requested in connect descriptor Failed.
- You are no longer connected to ORACLE
- Please connect again.
- Unable to start instance "orcl"
- You must start instance "orcl" manually
- Operation requires startup of instance "orcl" on database "physical"
- You must start instance "orcl" manually
- Switchover succeeded, new primary is "physical"
- [oracle@primary dbs]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 13 14:36:08 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected to an idle instance.
- SQL> startup mount
- ORACLE instance started.
- Total System Global Area 167772160 bytes
- Fixed Size 1218316 bytes
- Variable Size 71305460 bytes
- Database Buffers 92274688 bytes
- Redo Buffers 2973696 bytes
- Database mounted.
- SQL> alter database recover managed standby database disconnect from session;
- Database altered.
- SQL> select open_mode,name,database_role,switchover_status from v$database;
- OPEN_MODE NAME DATABASE_ROLE SWITCHOVER_STATUS
- ---------- --------- ---------------- --------------------
- MOUNTED ORCL PHYSICAL STANDBY NOT ALLOWED
- [oracle@physical ~]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 13 14:37:06 2011
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected to an idle instance.
- SQL> startup
- ORACLE instance started.
- Total System Global Area 167772160 bytes
- Fixed Size 1218316 bytes
- Variable Size 62916852 bytes
- Database Buffers 100663296 bytes
- Redo Buffers 2973696 bytes
- Database mounted.
- Database opened.
- SQL> select open_mode,name,database_role,switchover_status from v$database;
- OPEN_MODE NAME DATABASE_ROLE SWITCHOVER_STATUS
- ---------- --------- ---------------- --------------------
- READ WRITE ORCL PRIMARY SESSIONS ACTIVE
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/arch/physical_logs/
- Oldest online log sequence 15
- Next log sequence to archive 16
- Current log sequence 16
- SQL> alter system switch logfile;
- System altered.
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/arch/physical_logs/
- Oldest online log sequence 15
- Next log sequence to archive 17
- Current log sequence 17
- 備庫:
- SQL> select first_time,next_time,sequence#,applied from v$archived_log where sequence# >= 15;
- FIRST_TIME NEXT_TIME SEQUENCE# APP
- ------------------- ------------------- ---------- ---
- 2011-10-13:14:33:14 2011-10-13:14:38:16 15 YES
- 2011-10-13:14:38:16 2011-10-13:14:42:38 16 YES
5:DGMGRL報錯如下
- [oracle@physical u01]$ dgmgrl sys/123456@physical
- DGMGRL for Linux: Version 10.2.0.1.0 - Production
- Copyright (c) 2000, 2005, Oracle. All rights reserved.
- Welcome to DGMGRL, type "help" for information.
- Connected.
- DGMGRL> show configuration;
- Configuration
- Name: DG_YANG
- Enabled: YES
- Protection Mode: MaxPerformance
- Fast-Start Failover: DISABLED
- Databases:
- primary - Physical standby database
- physical - Primary database
- Current status for "DG_YANG":
- Warning: ORA-16608: one or more databases have warnings
- DGMGRL> show database physical statusreport;
- STATUS REPORT
- INSTANCE_NAME SEVERITY ERROR_TEXT
- DGMGRL> show database primary statusreport;
- STATUS REPORT
- INSTANCE_NAME SEVERITY ERROR_TEXT
- * WARNING ORA-16826: apply service state is inconsistent with the DelayMins property
- 原因:
- Oracle Error :: ORA-16826 apply service state is inconsistent with the DelayMins property
- Cause
- This warning was caused by one of the following reasons:
- - 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.
- - 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.
- Action
- 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.
- DGMGRL> show database primary DelayMins;
- DelayMins = '0'
- DGMGRL> edit database primary set property DelayMins=1;
- Property "delaymins" updated
- DGMGRL> edit database physical set property DelayMins=1;
- Property "delaymins" updated
- DGMGRL> show configuration;
- Configuration
- Name: DG_YANG
- Enabled: YES
- Protection Mode: MaxPerformance
- Fast-Start Failover: DISABLED
- Databases:
- primary - Physical standby database
- physical - Primary database
- Current status for "DG_YANG":
- SUCCESS
- DGMGRL> show database primary statusreport;
- STATUS REPORT
- INSTANCE_NAME SEVERITY ERROR_TEXT
2011年11月2日更新,之前提到在switchover中間會提示連不上數據庫,經過排查,發現是tnsnames.ora文件service_name配置不正確導致,參考文檔:
https://forums.oracle.com/forums/thread.jspa?threadID=307281