--本次环境为Oracle11.2.0.3 + Readhat 6.5 单实例环境,一个主库,一个物理备库
Data
Guard Broker基于分布式的管理框架,可以用来集中创建,管理,配置和监控data
guard。
客户端:Oracle
grid control和命令行工具DGMGRL。
服务端:DMON进程和配置文件。DMON进程的作用: 响应用户的请求,更新broker的配置文件,和data
guard配置中的其他服务器通信
-
配置要求:
-
在主库和备库上的COMPATIBLE参数必须设定为9.2.0或更高(11g2.0.3版本的值为11.2.0.0.0完全满足)。
-
必须有oracle网络支持,必须配置LOCAL_LISTENER静态监听注册。
-
GLOBAL_DBNAME属性必须设定为db_uniquename_DGMGRL。
-
DG_BROKER_START参数要设置为TRUE。
切换前DG示意图

配置详细步骤
1.主备库修改 dg_broker_config_file 参数,并启用broker
-
主库
-
alter system set dg_broker_config_file1='/u01/app/oracle/product/11.2.0/db_1/dbs/dr1orcl.dat';
-
alter system set dg_broker_config_file2='/u01/app/oracle/product/11.2.0/db_1/dbs/dr2orcl.dat';
-
备库
-
alter system set dg_broker_config_file1='/u01/app/oracle/product/11.2.0/db_1/dbs/dr1orcl.dat';
-
alter system set dg_broker_config_file2='/u01/app/oracle/product/11.2.0/db_1/dbs/dr2orcl.dat';
-
启用BROKER:主备库均执行
-
alter system set dg_broker_start=true scope=both;
-
--备注:RAC环境,建议dat文件放在asm共享磁盘上
2.创建并启用配置文件
-
主库上执行即可
-
[oracle@dg admin]$ dgmgrl connect sys/oracle@orcl;
-
添加主库
-
DGMGRL> create configuration orcltest as primary database is orcl connect identifier is orcl;
-
Configuration "orcltest" created with primary database "orcl"
-
#启用配置文件
-
DGMGRL> enable configuration;
-
#添加备库
-
DGMGRL> add database standby as connect identifier is standby;
-
DGMGRL> enable database standby;
-
#查看配置信息
-
DGMGRL> show configuration
-
Configuration - orcltest
-
Protection Mode: MaxPerformance
-
Databases:
-
orcl - Primary database
-
standby - Physical standby database
-
Fast-Start Failover: DISABLED
-
Configuration Status:
-
SUCCESS
3.查看主备库配置信息
-
主库
-
DGMGRL> show database verbose orcl;
-
-
Database - orcl
-
-
Role: PRIMARY
-
Intended State: TRANSPORT-ON
-
Instance(s):
-
orcl
-
-
Properties:
-
DGConnectIdentifier = 'orcl'
-
ObserverConnectIdentifier = ''
-
LogXptMode = 'SYNC'
-
DelayMins = '0'
-
Binding = 'optional'
-
MaxFailure = '0'
-
MaxConnections = '1'
-
ReopenSecs = '300'
-
NetTimeout = '30'
-
RedoCompression = 'DISABLE'
-
LogShipping = 'ON'
-
PreferredApplyInstance = ''
-
ApplyInstanceTimeout = '0'
-
ApplyParallel = 'AUTO'
-
StandbyFileManagement = 'AUTO'
-
ArchiveLagTarget = '0'
-
LogArchiveMaxProcesses = '4'
-
LogArchiveMinSucceedDest = '1'
-
DbFileNameConvert = ''
-
LogFileNameConvert = ''
-
FastStartFailoverTarget = 'standby'
-
InconsistentProperties = '(monitor)'
-
InconsistentLogXptProps = '(monitor)'
-
SendQEntries = '(monitor)'
-
LogXptStatus = '(monitor)'
-
RecvQEntries = '(monitor)'
-
SidName = 'orcl'
-
StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.110)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl_DGMGRL)(INSTANCE_NAME=orcl)(SERVER=DEDICATED)))'
-
StandbyArchiveLocation = '/u01/archivelog/'
-
AlternateLocation = ''
-
LogArchiveTrace = '0'
-
LogArchiveFormat = 'arch_%r_%t_%s.arc'
-
TopWaitEvents = '(monitor)'
-
-
Database Status:
-
SUCCESS
-
备库
-
DGMGRL> show database verbose standby
-
-
Database - standby
-
-
Role: PHYSICAL STANDBY
-
Intended State: APPLY-ON
-
Transport Lag: 0 seconds
-
Apply Lag: 0 seconds
-
Real Time Query: ON
-
Instance(s):
-
standby
-
-
Properties:
-
DGConnectIdentifier = 'standby'
-
ObserverConnectIdentifier = ''
-
LogXptMode = 'SYNC'
-
DelayMins = '0'
-
Binding = 'OPTIONAL'
-
MaxFailure = '0'
-
MaxConnections = '1'
-
ReopenSecs = '300'
-
NetTimeout = '30'
-
RedoCompression = 'DISABLE'
-
LogShipping = 'ON'
-
PreferredApplyInstance = ''
-
ApplyInstanceTimeout = '0'
-
ApplyParallel = 'AUTO'
-
StandbyFileManagement = 'AUTO'
-
ArchiveLagTarget = '0'
-
LogArchiveMaxProcesses = '5'
-
LogArchiveMinSucceedDest = '1'
-
DbFileNameConvert = '/u01/app/oracle/oradata/orcl/, /u01/app/oracle/oradata/standby/'
-
LogFileNameConvert = '/u01/app/oracle/oradata/orcl/, /u01/app/oracle/oradata/standby/'
-
FastStartFailoverTarget = 'orcl'
-
InconsistentProperties = '(monitor)'
-
InconsistentLogXptProps = '(monitor)'
-
SendQEntries = '(monitor)'
-
LogXptStatus = '(monitor)'
-
RecvQEntries = '(monitor)'
-
SidName = 'standby'
-
StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.112)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=standby_DGMGRL)(INSTANCE_NAME=standby)(SERVER=DEDICATED)))'
-
StandbyArchiveLocation = '/u01/archivelog/'
-
AlternateLocation = ''
-
LogArchiveTrace = '0'
-
LogArchiveFormat = 'arch_%r_%t_%s.arc'
-
TopWaitEvents = '(monitor)'
-
-
Database Status:
-
SUCCESS
-
--这里需要注意的一点是:
-
SERVICE_NAME=standby_DGMGRL 这个service_name参数,默认格式为db_unique_name_DGMGRL,如果这里采用默认格式,那么主备库的监听,就要配置静态监听。
-
静态监听中的GLOBAL_DBNAME 参数就要配置 db_unique_name_DGMGRL,监听配置及状态如下:
-
###备库监听配置信息(主库类似配置)
-
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.112)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = standby)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = standby)
)
(SID_DESC =
(GLOBAL_DBNAME = standby_DGMGRL)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = standby)
)
)
ADR_BASE_LISTENER = /u01/app/oracle
-
###备库监听状态如下(主库类似)
-
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 02-NOV-2016 16:12:34
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.112)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 02-NOV-2016 08:56:26
Uptime 0 days 7 hr. 16 min. 8 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/dg/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.112)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "standby" has 2 instance(s).
Instance "standby", status UNKNOWN, has 1 handler(s) for this service...
Instance "standby", status READY, has 1 handler(s) for this service...
Service "standbyXDB" has 1 instance(s).
Instance "standby", status READY, has 1 handler(s) for this service...
Service "standby_DGB" has 1 instance(s).
Instance "standby", status READY, has 1 handler(s) for this service...
Service "standby_DGMGRL" has 1 instance(s).
Instance "standby", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
手工更改service_name参数值
--如果不采用静态监听的方式,那么就要用手工更改该参数的值,命令格式,可以用help帮助提示,help edit
-
DGMGRL> edit database htz set property StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.110)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)(INSTANCE_NAME=htz)(SERVER=DEDICATED)))';
-
Property "staticconnectidentifier" updated
-
DGMGRL> edit database htzb set property StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.112)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=standby)(INSTANCE_NAME=standby)(SERVER=DEDICATED)))';
-
Property "staticconnectidentifier" updated
4.switchover切换测试
-
开始切换,原备库切换为主库
-
DGMGRL> switchover to standby
-
Performing switchover NOW, please wait...
-
New primary database "standby" is opening...
-
Operation requires shutdown of instance "orcl" on database "orcl"
-
Shutting down instance "orcl"...
-
ORACLE instance shut down.
-
Operation requires startup of instance "orcl" on database "orcl"
-
Starting instance "orcl"...
-
ORACLE instance started.
-
Database mounted.
-
Database opened.
-
Switchover succeeded, new primary is "standby"
手工查看原主备库成功切换,查看归档日志应用情况正常
-
#查看主备库状态
-
set lines 1000 pages 1000
-
select db_unique_name,open_mode,database_role,protection_mode,switchover_status from v$database;
-
-
#备库上查看归档日志应用情况
-
set lines 1000 pages 1000
-
col NAME for a50
-
select NAME,THREAD#,SEQUENCE#,to_char(FIRST_TIME,'yyyy-mm-dd hh24:mi:ss') FIRST_TIME,APPLIED,
-
to_char(NEXT_TIME,'yyyy-mm-dd hh24:mi:ss') NEXT_TIME from v$archived_log
切换后DG示意图

---备注:经过实际测试,broker方式来切换主备库,确实教手工敲命令行方式方便一些,在进行主库升级打补丁时,能简化操作,也就是能减少变更的时间,这为大半夜做变更的DBA们来说是一件很欣慰的事情。但是,观察我们网管中心这么多ADG环境,貌似没有该配置,不知为何?是怕丢失数据?
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28551528/viewspace-2127523/
,如需转载,请注明出处,否则将追究法律责任。