公司所有的DG环境都用到了BROKER这个东西,今天我也在VM来测试一下这个玩意。不过听说在生产中用得比较少,不知道我们公司为什么全部上的这个东西。
测试环境:OS REDHAT 5.6 X86_64 ,DB 11.2.0.2
DG的测试参考之前写的BLOG:
11GR2 搭建活动的物理DG/DATAGRUAD (READ ONLY模式)
1,修改
dg_broker_config_file参数。
如果是在RAC环境中,这个把这个文件把到共享的存储上面,如果有ASM可以放到ASM中。 主库:
- #这里跟官方给的名字有一点不一样htz1.dat这里官方要求是drc<db_uniqun_name>.dat,但是我这里也没有报错。
- SQL> alter system set dg_broker_config_file1='/u01/app/oracle/oradata/htz/htz1.dat';
- System altered.
- SQL>
- SQL> alter system set dg_broker_config_file2='/u01/app/oracle/oradata/htz/htz2.dat';
- System altered.
备库:
- SQL> alter system set dg_broker_config_file1='/u01/app/oracle/oradata/htz/htz1.dat';
- System altered.
- SQL> alter system set dg_broker_config_file2='/u01/app/oracle/oradata/htz/htz2.dat';
- System altered.
启用BROKER:
在两个数据库上面都执行:
- SQL> alter system set dg_broker_start=true scope=both;
- System altered.
在其中任意一台做下面的操作就可以了,另它安装了client的客户端也是可以的.
- [oracle@11g admin]$ dgmgrl
- DGMGRL for Linux: Version 11.2.0.2.0 - 64bit Production
- Copyright (c) 2000, 2009, Oracle. All rights reserved.
- Welcome to DGMGRL, type "help" for information.
- #连接数据库
- DGMGRL> connect sys/oracle@htz
- Connected.
- #help是帮忙命令,这点做得很好,不像sqlplus中。
- DGMGRL> help create
- Creates a broker configuration
- Syntax:
- CREATE CONFIGURATION <configuration name> AS
- PRIMARY DATABASE IS <database name>
- CONNECT IDENTIFIER IS <connect identifier>;
- #创建一个配置文件,这里一定要记得是连接到当前的主数据库
- DGMGRL> create configuration htz as primary database is htz connect identifier is htz;
- Configuration "htz" created with primary database "htz"
- #启用配置文件
- DGMGRL> enable configuration;
- Enabled.
- #增加备库到配置文件中
- DGMGRL> help add
- Adds a standby database to the broker configuration
- Syntax:
- ADD DATABASE <database name>
- [AS CONNECT IDENTIFIER IS <connect identifier>]
- [MAINTAINED AS {PHYSICAL|LOGICAL}];
- DGMGRL> add database htzb as connect identifier is htzb;
- Database "htzb" added
- #启用备库
- DGMGRL> enable database htzb;
- Enabled.
- #查看配置文件
- DGMGRL> show configuration
- Configuration - htz
- Protection Mode: MaxAvailability
- Databases:
- htz - Primary database
- htzb - Physical standby database
- Fast-Start Failover: DISABLED
- Configuration Status:
- SUCCESS
- #查看某个数据库的配置消息,其中很多参数我们都可以在sqlplus修改的。
- DGMGRL> show database verbose htz;
- Database - htz
- Role: PRIMARY
- Intended State: TRANSPORT-ON
- Instance(s):
- htz
- Properties:
- DGConnectIdentifier = 'htz'
- 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 = 'MANUAL'
- ArchiveLagTarget = '0'
- LogArchiveMaxProcesses = '4'
- LogArchiveMinSucceedDest = '1'
- DbFileNameConvert = '/u01/app/oracle/oradata/htz/, /u01/app/oracle/oradata/htz/'
- LogFileNameConvert = '/u01/app/oracle/oradata/htz/, /u01/app/oracle/oradata/htz/'
- FastStartFailoverTarget = ''
- InconsistentProperties = '(monitor)'
- InconsistentLogXptProps = '(monitor)'
- SendQEntries = '(monitor)'
- LogXptStatus = '(monitor)'
- RecvQEntries = '(monitor)'
- SidName = 'htz'
- #这里要注意了。broker里面的连接的service_name是<db_unique_name>_DGMGRL,因为我们
- #静态监听中的GLOBAL_NAME是DB_UNIQUE_NAME,所以这里我们要修改
StaticConnectIdentifier #不然在切换的时候会报错的。
- StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=11g)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=HTZ_DGMGRL)(INSTANCE_NAME=htz)(SERVER=DEDICATED)))'
- StandbyArchiveLocation = '/u01/app/oracle/arch/htz/'
- AlternateLocation = ''
- LogArchiveTrace = '0'
- LogArchiveFormat = '%t_%s_%r.dbf'
- TopWaitEvents = '(monitor)'
- Database Status:
- SUCCESS
- DGMGRL> show database verbose htzb;
- Database - htzb
- Role: PHYSICAL STANDBY
- Intended State: APPLY-ON
- Transport Lag: 0 seconds
- Apply Lag: 0 seconds
- Real Time Query: ON
- Instance(s):
- htz
- Properties:
- DGConnectIdentifier = 'htzb'
- 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 = 'MANUAL'
- ArchiveLagTarget = '0'
- LogArchiveMaxProcesses = '4'
- LogArchiveMinSucceedDest = '1'
- DbFileNameConvert = '/u01/app/oracle/oradata/htz/, /u01/app/oracle/oradata/htz/'
- LogFileNameConvert = '/u01/app/oracle/oradata/htz/, /u01/app/oracle/oradata/htz/'
- FastStartFailoverTarget = ''
- InconsistentProperties = '(monitor)'
- InconsistentLogXptProps = '(monitor)'
- SendQEntries = '(monitor)'
- LogXptStatus = '(monitor)'
- RecvQEntries = '(monitor)'
- SidName = 'htz'
- StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=11gdg)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=HTZB_DGMGRL)(INSTANCE_NAME=htz)(SERVER=DEDICATED)))'
- StandbyArchiveLocation = '/u01/app/oracle/arch/htz/'
- AlternateLocation = ''
- LogArchiveTrace = '0'
- LogArchiveFormat = '%t_%s_%r.dbf'
- TopWaitEvents = '(monitor)'
- Database Status:
- SUCCESS
修改 StaticConnectIdentifier参数,记得两个数据库都要修改。
- DGMGRL> edit database htz set property StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.30)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=htz)(INSTANCE_NAME=htz)(SERVER=DEDICATED)))';
- Property "staticconnectidentifier" updated
- DGMGRL> edit database htzb set property StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.31)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=htzb)(INSTANCE_NAME=htz)(SERVER=DEDICATED)))';
- Property "staticconnectidentifier" updated
开始切换:
- DGMGRL> show configuration
- Configuration - htz
- Protection Mode: MaxAvailability
- Databases:
- #注意这里hta是主数据库
- htz - Primary database
- htzb - Physical standby database
- Fast-Start Failover: DISABLED
- Configuration Status:
- SUCCESS
- #开始切换
- DGMGRL> switchover to htzb;
- Performing switchover NOW, please wait...
- New primary database "htzb" is opening...
- Operation requires shutdown of instance "htz" on database "htz"
- Shutting down instance "htz"...
- ORACLE instance shut down.
- Operation requires startup of instance "htz" on database "htz"
- Starting instance "htz"...
- ORACLE instance started.
- Database mounted.
- Database opened.
- Switchover succeeded, new primary is "htzb"
- #查看状态
- DGMGRL> show configuration;
- Configuration - htz
- Protection Mode: MaxAvailability
- Databases:
- #htzb已经切换成主数据库了,切换成功
- htzb - Primary database
- htz - Physical standby database
- Fast-Start Failover: DISABLED
- Configuration Status:
- SUCCESS