Oracle Data Guard Broker的配置及一些说明,参考Oracle 官网文档:
Oracle Data Guard 快速启动故障切换指南
http://www.oracle.com/technology/global/cn/pub/articles/smiley-fsfo.html
测试平台: Redhat 5.4 + Oracle 10gR2+ Physical Standby
一. Data Guard Broker 相关概念
1.1 Broker
Data Guard环境设置了Broker后,当主库出现一下情况,Broker就会自动进行主备库的切换。
1) Instance Failure
2) Shutdown Abort
3) Offline Datafiles due to I/O error
4) Network disconnection
切换时,Observer会将备库变成主库。 同时Observer 通过应用Flashback log将原来的主库变成备库。 所以,Data Guard Broker必须开启Flashback,同时将DG 配置在maximum availability模式。
Data Guard Broker 会在所有的主备库上使用自己的DMON进程和配置文件进行通信。当我们将DG_BROKER_START 设置为true之后,DMON进程就会启动。 对于Broker的配置文件,我们可以通过Enterprise Manger 或者使用DGMGRL命令进行创建。
Broker的配置文件有自己的参数和设置。 Data Guard 允许有多分配置文件,所以我们需要在DG_BROKER_CONFIG_FILEn 参数里指定正确的配置文件。 要注意的是, 这个控制文件是二进制文件,不要手动去修改它, 这样会破坏这个文件。
如果是RAC 环境, 所有的实例有一份Broker 配置文件。 该文件放在共享设备上。
Broker的更多内容参考:
Interaction Between the Data Guard Broker and a Data Guard Configuration [ID 249703.1]
http://blog.csdn.net/xujinyang/article/details/6925015
1.2 Maximum Availability模式
最高可用性(Maximum availability):这种模式在不影响Primary数据库可用前提下,提供最高级别的数据保护策略。其实现方式与最大保护模式类似,也是要求本地事务在提交前必须至少写入一台Standby数据库的Standby Redologs中,不过与最大保护模式不同的是,如果出现故障导致Standby数据库无法访问,Primary数据库并不会被Shutdown,而是自动转为最高性能模式,等Standby数据库恢复正常之后,Primary数据库又会自动转换成最高可用性模式。
Maximum protection/AVAILABILITY模式必须满足以下条件:
(1)Redo Archival Process: LGWR
(2)Network Tranmission mode: SYNC
(3)Disk Write Option: AFFIRM
(4)Standby Redo Logs: Yes
(5)standby database type: Physical Only
即Standby Database 必须配置Standby Redo Log,而Primary Database必须使用LGWR,SYNC,AFFIRM 方式归档到Standby Database.
如:
SQL> alter system set log_archive_dest_2='service=orcl_st lgwr sync AFFIRM';
注意: 主库的保护模式修改之后,备库的模式也会改变,和主库保持一致。
在此对LGWR 进程的SYNC 方式做下说明:
(1)Primary Database 产生的Redo 日志要同时写道日志文件和网络。也就是说LGWR进程把日志写到本地日志文件的同时还要发送给本地的LNSn进程(Network Server Process),再由LNSn(LGWR Network Server process)进程把日志通过网络发送给远程的目的地,每个远程目的地对应一个LNS进程,多个LNS进程能够并行工作。
(2)LGWR 必须等待写入本地日志文件操作和通过LNSn进程的网络传送都成功,Primary Database 上的事务才能提交,这也是SYNC的含义所在。
(3)Standby Database的RFS进程把接收到的日志写入到Standby Redo Log日志中。
(4) Primary Database的日志切换也会触发Standby Database 上的日志切换,即Standby Database 对Standby Redo Log的归档,然后触发Standby Database 的MRP或者LSP 进程恢复归档日志。
因为Primary Database 的Redo 是实时传递的,于是Standby Database 端可以使用两种恢复方法:
实时恢复(Real-Time Apply): 只要RFS把日志写入Standby Redo Log 就会立即进行恢复;
归档恢复: 在完成对Standby Redo Log 归档才触发恢复。
Primary Database默认使用ARCH进程,如果使用LGWR进程必须明确指定。使用LGWR SYNC方式时,可以同时使用NET_TIMEOUT参数,这个参数单位是秒,代表如果多长时间内网络发送没有响应,LGWR 进程会抛出错误。
示例:
alter system set log_archive_dest_2 = 'SERVICE=ST LGWR SYNC NET_TIMEOUT=30' scope=both;
Oracle Data Guard 理论知识, 更多内容参考:
http://blog.csdn.net/xujinyang/article/details/6833263
二. 用DGMGRL配置物理standby的Broker示例
Oracle 10g官网文档参考:
IMPLEMENTING FAST-START FAILOVER IN 10GR2 DATAGUARD BROKER ENVIRONMENT [ID 359555.1]
http://blog.csdn.net/xujinyang/article/details/6833180
Oracle 9i 官网文档参考:
Setup and maintenance of Data Guard Broker using DGMGRL [ID 201669.1]
http://blog.csdn.net/xujinyang/article/details/6925035
这篇文章主要介绍Broker的配置,关于Data Guard的配置参考:
Oracle Data Guard Linux 平台 Physical Standby 搭建实例
http://blog.csdn.net/xujinyang/article/details/6829555
Oracle Data Guard Linux 平台 Logical Standby 创建实例
http://blog.csdn.net/xujinyang/article/details/6829546
在这里补充一点,我以前配置DG,喜欢使用默认方式,这样配置是非常简单的。 但是最好还是把所有参数写全,其实也没有几个参数需要配置。 关于参数的详细参考:
Oracle Data Guard 理论知识
http://blog.csdn.net/xujinyang/article/details/6833263
在pfile里添加如下参数,用pfile启动后,在创建spfile:
####主库参数######
*.DB_NAME ='orcl';
*.DB_UNIQUE_NAME='orcl_pd' --监听中配置的
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_st)'
--列出DG中所有DB_UNIQUE_NAME
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_pd'
*.LOG_ARCHIVE_DEST_2='service=orcl_st LGWR SYNC AFFIRM NET_TIMEOUT=30 DB_UNIQUE_NAME=orcl_st'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
#####备库参数#######
*.FAL_SERVER=orcl_st
*.FAL_CLIENT=orcl_pd
*.standby_file_management='AUTO'
*.standby_archive_dest='/u01/archive'
#如果主备库目录不同,还需要添加:
*.log_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
*.db_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
在主备库的pfile里把如下参数都添加进去,因为切换之后还是需要使用的。 不过主备库相应的目录和实例需要调整。
注意:必须配置local_listener,由各实例参数local_listener解析出来的监听地址必须能被所有成员访问 local_listener
主库: *. local_listener='orcl_pd;
备库: *. local_listener='orcl_st;
2.1 切换Data Guard到Maximum availability模式
默认情况下是Maximum performance,所以我们需要调整。
查看主备库log_archive_dest_2 参数:
(1)主库:
SQL> show parameter log_archive_dest_2
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2 string SERVICE=orcl_st
(2)备库:
SQL> show parameter log_archive_dest_2
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2 string SERVICE=orcl_pd
修改主备库的log_archive_dest_2参数:
(1)主库:
SQL> alter system set log_archive_dest_2='service=orcl_st LGWR SYNC AFFIRM NET_TIMEOUT=30 DB_UNIQUE_NAME=orcl_st';
System altered.
SQL> show parameter log_archive_dest_2
(2)备库:
SQL> alter system set log_archive_dest_2 = 'SERVICE=orcl_pd LGWR SYNC NET_TIMEOUT=30 AFFIRM DB_UNIQUE_NAME=orcl_pd' scope=both;
System altered.
SQL> show parameter log_archive_dest_2
在主备库查看模式:
SQL> select protection_mode,protection_level from v$database;
PROTECTION_MODE PROTECTION_LEVEL
-------------------- --------------------
MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
主备库都执行:
注意, 切换模式要在非open 状态执行,所以主库需要shutdown,在启动到mount后,在执行命令,备库直接执行即可。
SQL> alter database set standby database to maximize availability;
Database altered.
SQL> select protection_mode,protection_level from v$database;
PROTECTION_MODE PROTECTION_LEVEL
-------------------- --------------------
MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
2.2 启动Flashback
数据库的Flashback Database功能缺省是关闭的。我们需要启动它。
可以通过如下SQL 查看:
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
在启用Flashback database 之前,我们需要先设定闪回区:
在主备库查看:
SQL> show parameter db_recovery_file_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /u01/app/oracle/flash_recovery_area
db_recovery_file_dest_size big integer 2G
我这里是设置过了,如果没有设置,可以用以下语句进行设置:
Alter system set db_recovery_file_dest_size=<integer>[<k><M><G>];
Alter system set db_recovery_file_dest=<path_to_flashabck_logs>;
启动flashback database.
主库: 这个操作也需要在非open 状态执行。 主库需要shutdown后,启动到mount 状态执行。
SQL> Alter database flashback on;
备库:需要先取消recover 进程,不然会报错。
SQL> Alter database flashback on;
Alter database flashback on
*
ERROR at line 1:
ORA-01153: an incompatible media recovery is active
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> Alter database flashback on;
Database altered.
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
SQL> alter database recover managed standby database disconnect from session;
Database altered.
详细内容参考:
Oracle Flashback 技术 总结
http://blog.csdn.net/xujinyang/article/details/6830438
2.3 安装DGMGRL
这一步是官网上建议安装的。 在另一台观察机器observer 上安装DGMGRL。就是安装一个Oracle 的客户端。 并在observer machine上配置相关的参数。包括配置监听, 使这台机器能访问主备库的实例。 然后通过这个observer来判断主备库的状态。 如果主库出现问了, 那么observer 就会切换主备库。
放在另一台机器的原因也很明显,如果放在主库上,如果主库系统崩溃了,那么Observer也就失效了。
在这个实验中,我不在单独在其他机器上安装DGMGRL命令。 我直接在备库的系统上配置这个observer.
2.4 设置broker 参数
在主备库查看dg_broker_start参数:
SQL> show parameter dg_broker_start
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
dg_broker_start boolean FALSE
SQL> alter system set dg_broker_start = true scope=both;
System altered.
SQL> show parameter dg_broker_start
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
dg_broker_start boolean TRUE
SQL>
2.5 配置Listener.ora 文件
To enable DGMGRL to restart instances during the course of broker operations, a service with a specific name must be statically registered with the local listener of each instance. A static service registration is also required to enable the observer to restart instances as part of automatic reinstatement of the old primary database after a fast-start failover has occurred. The broker uses a default name for the GLOBAL_DBNAME attribute of db_unique_name_DGMGRL.db_domain.
From:http://download.oracle.com/docs/cd/E18283_01/server.112/e17023/install.htm
主备库的Listener.ora 文件都修改成如下格式:
[oracle@dg1 admin]$ cat listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(GLOBAL_DBNAME = orcl)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl_pd_DGMGRL)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = orcl)
)
)
注意这里的GLOBAL_DBNAME参数格式:
<db_unique_name>_DGMGRL.<db_domain> 的连接。
备库改成备库的db_unique_name 就可以了。并且db_unique_name 大小写敏感。 其他一样。
或者使用net manager工具,在listeners选项下,选择Database Services服务,添加一下。
最好不要忘了用: lsnrctl reload 命令重新加载一下。
2.6 设置FAST_START FAILOVER
这里是测试,不在用另一台机器来做observer。 故在备库上配置Broker.
[oracle@dg2 /]$ dgmgrl
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.
DGMGRL> connect sys/oracle@orcl_pd;
Connected.
DGMGRL> help create
Create a broker configuration
Syntax:
CREATE CONFIGURATION <configuration name> AS
PRIMARY DATABASE IS <database name> -- db_unique_name
CONNECT IDENTIFIER IS <connect identifier>; -- 监听中配置的名称
DGMGRL> create configuration 'OrclBroker' as primary database is 'orcl_pd' connect identifier is orcl_pd;
Configuration "OrclBroker" created with primary database "orcl_pd"
DGMGRL> help add
Add 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 'orcl_st' as connect identifier is orcl_st maintained as physical;
Database "orcl_st" added
DGMGRL> show configuration
Configuration
Name: OrclBroker
Enabled: NO
Protection Mode: MaxAvailability
Fast-Start Failover: DISABLED
Databases:
orcl_pd - Primary database
orcl_st - Physical standby database
Current status for "OrclBroker":
DISABLED
如果出现这种错误,处理方法参考:
ORA-16796: one or more properties could not be imported from the database [ID 358040.1]
http://blog.csdn.net/xujinyang/article/details/6833155
现在会在主库的$ORACLE_HOME/dbs/下生成2个配置文件:dr1orcl_pd.dat 和dr2orcl_pd.dat. 这2个文件的位置有如下参数指定:
SQL> show parameter dg_broker_config_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
dg_broker_config_file1 string /u01/app/oracle/product/10.2.0
/db_1/dbs/dr1orcl_pd.dat
dg_broker_config_file2 string /u01/app/oracle/product/10.2.0
/db_1/dbs/dr2orcl_pd.dat
[oracle@dg1 dbs]$ pwd
/u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@dg1 dbs]$ ls
dr1orcl_pd.dat hc_orcl.dat init.ora lkORCL orapworcl
dr2orcl_pd.dat initdw.ora initorcl.ora lkORCL_PD spfileorcl.ora
DGMGRL 的日志位置在:
[oracle@dg2 admin]$ cd /u01/app/oracle/admin/orcl/bdump/
[oracle@dg2 bdump]$ ls
alert_orcl.log drcorcl.log
[oracle@dg2 bdump]$ cat dr
现在我们启用configuration:
DGMGRL> enable configuration
Enabled.
启用之后,在备库的相关目录下也会生成这2个文件。 这2个文件在启用之前是没有生成的。
DGMGRL> show configuration
Configuration
Name: OrclBroker
Enabled: YES
Protection Mode: MaxAvailability
Fast-Start Failover: DISABLED --FSFO 是禁用的
Databases:
orcl_pd - Primary database
orcl_st - Physical standby database
Current status for "OrclBroker":
SUCCESS
DGMGRL> show database verbose 'orcl_pd';
Database
Name: orcl_pd
Role: PRIMARY
Enabled: YES
Intended State: ONLINE
Instance(s):
orcl
Properties:
InitialConnectIdentifier = 'orcl_pd'
LogXptMode = 'ASYNC' --状态不正确,等会调整
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 = 'dg1'
SidName = 'orcl'
LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.2)(PORT=1521))'
StandbyArchiveLocation = '/u01/archive'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
LatestLog = '(monitor)'
TopWaitEvents = '(monitor)'
Current status for "orcl_pd":
SUCCESS
DGMGRL> show database verbose 'orcl_st'
Database
Name: orcl_st
Role: PHYSICAL STANDBY
Enabled: YES
Intended State: ONLINE
Instance(s):
orcl
Properties:
InitialConnectIdentifier = 'orcl_st'
LogXptMode = 'SYNC'
Dependency = ''
DelayMins = '0'
Binding = 'OPTIONAL'
MaxFailure = '0'
MaxConnections = '1'
ReopenSecs = '300'
NetTimeout = '30'
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 = 'dg2'
SidName = 'orcl'
LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.3)(PORT=1521))'
StandbyArchiveLocation = '/u01/archive'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
LatestLog = '(monitor)'
TopWaitEvents = '(monitor)'
Current status for "orcl_st":
SUCCESS
在enable FSFO 之前,需要注意LogXptMode的状态,必须为SYNC。 刚才看到orcl_pd 的状态不正确,我们调整一下:
DGMGRL> edit database orcl_pd set property logxptmode=sync;
Property "logxptmode" updated
DGMGRL> show database verbose orcl_pd
Database
Name: orcl_pd
Role: PRIMARY
Enabled: YES
Intended State: ONLINE
Instance(s):
orcl
Properties:
InitialConnectIdentifier = 'orcl'
LogXptMode = 'sync'
Dependency = ''
...
不然在启用FSFO时,会遇到如下错误:
ORA-16651: requirements not met for enabling Fast-Start Failover
ORA-16651: | requirements not met for enabling Fast-Start Failover |
Cause: | The attempt to enable Fast-Start Failover could not be completed because one or more requirements have not been met: - The Data Guard configuration must be in MaxAvailability protection mode. - The LogXptMode property for both the primary database and the Fast-Start Failover target standby database must be SYNC. - The primary database and the Fast-Start Failover target standby database must both have flashback enabled. - No valid target standby database was specified in the primary database's FastStartFailoverTarget property prior to the attempt to enable Fast-Start Failover, and more than one standby database exists in the Data Guard configuration. |
Action: | Retry the attempted command after correcting the issue: - Set the Data Guard configuration to MaxAvailability protection mode. - Ensure that the LogXptMode property for both the primary database and the Fast-Start Failover target standby database are SYNC. - Ensure that both the primary database and the Fast-Start Failover target standby database have flashback enabled. - Set the primary database's FastStartFailoverTarget property to the db_unique_name value of the desired target standby database add the desired target standby database's FastStartFailoverTarget property to the db_unique_name value of the primary database. |
启用FSFO:
DGMGRL> enable fast_start failover;
Enabled.
DGMGRL> show configuration verbose
Configuration
Name: OrclBroker
Enabled: YES
Protection Mode: MaxAvailability
Fast-Start Failover: ENABLED
Databases:
orcl_pd - Primary database
orcl_st - Physical standby database
- Fast-Start Failover target
Fast-Start Failover
Threshold: 30 seconds --默认值太小,等会改成120s
Observer: (none)
Current status for "OrclBroker":
Warning: ORA-16608: one or more databases have warnings -- 警告因为Observer没有启动, 这个从DGMGRL 日志中可以看到。
DGMGRL> edit configuration set property FastStartFailoverThreshold=120;
Property "faststartfailoverthreshold" updated
DGMGRL> show database verbose orcl_pd
Database
Name: orcl_pd
Role: PRIMARY
Enabled: YES
Intended State: ONLINE
Instance(s):
orcl
Properties:
InitialConnectIdentifier = 'orcl'
LogXptMode = 'sync'
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 = 'orcl_st'
StatusReport = '(monitor)'
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
SendQEntries = '(monitor)'
LogXptStatus = '(monitor)'
RecvQEntries = '(monitor)'
HostName = 'dg1'
SidName = 'orcl'
LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.2)(PORT=1521))'
StandbyArchiveLocation = '/u01/archive'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
LatestLog = '(monitor)'
TopWaitEvents = '(monitor)'
Current status for "orcl_pd":
Warning: ORA-16819: Fast-Start Failover observer not started -- 从这里也可以清楚的看出问题
启动Observer
DGMGRL> start observer
Observer started
注意,启动之后,该前台进程不会退出,会一直挂在这。 直到从其他窗口关闭。
默认情况下,observer会创建一个二进制的文件 fsfo.dat来保存主库和备库的连接信息。 这个文件会在调用dgmgrl命令的当前窗口下生成。
2.7 验证
主库:
SQL> select fs_failover_observer_present,fs_failover_observer_host,fs_failover_threshold from v$database;
FS_FAIL FS_FAILOVER_OBSERVER FS_FAILOVER_THRESHOLD
------- -------------------- ---------------------
YES dg2 120
备库:
SQL> select fs_failover_observer_present,fs_failover_observer_host,fs_failover_threshold from v$database;
FS_FAIL FS_FAILOVER_OBSERVER FS_FAILOVER_THRESHOLD
------- -------------------- ---------------------
YES dg2 120
[oracle@dg2 dbs]$ dgmgrl
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.
DGMGRL> connect sys/oracle@orcl_pd;
Connected.
DGMGRL> show configuration verbose;
Configuration
Name: OrclBroker
Enabled: YES
Protection Mode: MaxAvailability
Fast-Start Failover: ENABLED
Databases:
orcl_pd - Primary database
orcl_st - Physical standby database
- Fast-Start Failover target
Fast-Start Failover
Threshold: 120 seconds
Observer: dg2
Current status for "OrclBroker":
SUCCESS
DGMGRL> show database verbose orcl_pd;
Database
Name: orcl_pd
Role: PRIMARY
Enabled: YES
Intended State: ONLINE
Instance(s):
orcl
Properties:
InitialConnectIdentifier = 'orcl'
LogXptMode = 'sync'
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 = 'orcl_st'
StatusReport = '(monitor)'
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
SendQEntries = '(monitor)'
LogXptStatus = '(monitor)'
RecvQEntries = '(monitor)'
HostName = 'dg1'
SidName = 'orcl'
LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.2)(PORT=1521))'
StandbyArchiveLocation = '/u01/archive'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
LatestLog = '(monitor)'
TopWaitEvents = '(monitor)'
Current status for "orcl_pd":
SUCCESS
DGMGRL> show database verbose orcl_st;
Database
Name: orcl_st
Role: PHYSICAL STANDBY
Enabled: YES
Intended State: ONLINE
Instance(s):
orcl
Properties:
InitialConnectIdentifier = 'orcl_st'
LogXptMode = 'SYNC'
Dependency = ''
DelayMins = '0'
Binding = 'OPTIONAL'
MaxFailure = '0'
MaxConnections = '1'
ReopenSecs = '300'
NetTimeout = '30'
LogShipping = 'ON'
PreferredApplyInstance = ''
ApplyInstanceTimeout = '0'
ApplyParallel = 'AUTO'
StandbyFileManagement = 'AUTO'
ArchiveLagTarget = '0'
LogArchiveMaxProcesses = '2'
LogArchiveMinSucceedDest = '1'
DbFileNameConvert = ''
LogFileNameConvert = ''
FastStartFailoverTarget = 'orcl_pd'
StatusReport = '(monitor)'
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
SendQEntries = '(monitor)'
LogXptStatus = '(monitor)'
RecvQEntries = '(monitor)'
HostName = 'dg2'
SidName = 'orcl'
LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.3)(PORT=1521))'
StandbyArchiveLocation = '/u01/archive'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
LatestLog = '(monitor)'
TopWaitEvents = '(monitor)'
Current status for "orcl_st":
SUCCESS
2.8 验证自动切换
在前面提到,在一下情况会发生切换:
1) Instance Failure
2) Shutdown Abort
3) Offline Datafiles due to I/O error
4) Network disconnection
所以我们这里模拟主库shutdown的情况,我们在主库执行shutdown abort 在查看主备库的情况。
(1)先在客户端配置一下TAF
在tnsnames.ora 文件里添加如下参数:
TAFTEST=
(DESCRIPTION=
(LOAD_BALANCE=on)
(FAILOVER=on)
(ADDRESS=
(PROTOCOL=tcp)
(HOST=192.168.3.2)
(PORT=1521))
(ADDRESS=
(PROTOCOL=tcp)
(HOST=192.168.3.3)
(PORT=1521))
(CONNECT_DATA=
(SERVICE_NAME=orcl)
(FAILOVER_MODE=
(TYPE=select)
(METHOD=basic))))
然后通过客户端连接这个是里,连接上后我们查看一下:
C:/Users/Administrator.DavidDai>sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on 星期一 12月 13 16:56:33 2010
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> conn sys/oracle@taftest as sysdba;
已连接。
SQL> select db_unique_name from v$database;
DB_UNIQUE_NAME
------------------------------
orcl_pd
SQL> select name from v$database;
NAME
---------
ORCL
设置TAF之后,当Data Guard 切换之后,我们在客户端不需要做什么修改,还可以继续连接数据库。 关于TAF 的内容,参考:
Oracle Transparent Application Failover(TAF) 说明
http://blog.csdn.net/xujinyang/article/details/6831349
(2)shutdown about 主库
SQL> shutdown abort
ORACLE instance shut down.
我这里是采用shutdown 来验证,当然也可以用switchover to orcl_st 来进行切换。 这种做法可以参考:
Oracle Data Guard 快速启动故障切换指南
http://www.oracle.com/technology/global/cn/pub/articles/smiley-fsfo.html
(3)查看Broker log
2分钟之后开始切换,我们可以从主备库observer的log中查看:
原备库:
[oracle@dg2 bdump]$ pwd
/u01/app/oracle/admin/orcl/bdump
[oracle@dg2 bdump]$ tail -100 drcorcl.log
DG 2010-12-14-01:03:55 0 2 0 Database Resource[IAM=PRIMARY]: SetState READ-WRITE-XPTON, phase BUILD-UP, External Cond GRACEFUL-FAIL-OVER-PHYS_STBY, Target Site Handle 0x02001000
DG 2010-12-14-01:03:55 0 2 0 Executing SQL [ALTER SYSTEM SET standby_archive_dest='' SCOPE=BOTH sid='orcl']
DG 2010-12-14-01:03:55 0 2 0 SQL [ALTER SYSTEM SET standby_archive_dest='' SCOPE=BOTH sid='orcl'] Executed successfully
DG 2010-12-14-01:03:55 0 2 0 Executing SQL [ALTER SYSTEM SET log_archive_dest_1='location="/u01/archive"', 'valid_for=(ONLINE_LOGFILE,ALL_ROLES)' scope=both sid='orcl' ]
DG 2010-12-14-01:03:55 0 2 0 SQL [ALTER SYSTEM SET log_archive_dest_1='location="/u01/archive"', 'valid_for=(ONLINE_LOGFILE,ALL_ROLES)' scope=both sid='orcl' ] Executed successfully
DG 2010-12-14-01:03:55 0 2 0 Executing SQL [ALTER SYSTEM SET log_archive_dest_state_1='ENABLE' SCOPE=BOTH sid='orcl']
DG 2010-12-14-01:03:55 0 2 0 SQL [ALTER SYSTEM SET log_archive_dest_state_1='ENABLE' SCOPE=BOTH sid='orcl'] Executed successfully
DG 2010-12-14-01:03:55 0 2 0 Executing SQL [ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE AVAILABILITY]
DG 2010-12-14-01:03:55 0 2 0 SQL [ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE AVAILABILITY] Executed successfully
DG 2010-12-14-01:03:55 0 2 0 Set log transport destination: SetState ONLINE, phase BUILD-UP, External Cond GRACEFUL-FAIL-OVER-PHYS_STBY
DG 2010-12-14-01:03:55 0 2 0 Executing SQL [ALTER DATABASE OPEN]
已经完成了切换。
在客户端查看一下:
SQL> conn sys/oracle@taftest as sysdba;
已连接。
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
orcl
SQL> select db_unique_name from v$database;
DB_UNIQUE_NAME
------------------------------
orcl_st
在原来observer 启动的地方也会有提示:
DGMGRL> start observer
Observer started
01:03:01.88 Tuesday, December 14, 2010
Initiating fast-start failover to database "orcl_st"...
Performing failover NOW, please wait...
Failover succeeded, new primary is "orcl_st"
01:04:53.38 Tuesday, December 14, 2010
原来的备库:
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
READ WRITE PRIMARY
SQL> select fs_failover_status from v$database;
FS_FAILOVER_STATUS
---------------------
REINSTATE REQUIRED -- 表明原来的主库还没有被切换为备库
用dgmgrl连接到备库看看:
[oracle@dg2 dbs]$ dgmgrl
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.
DGMGRL> connect sys/oracle@orcl_st;
Connected.
DGMGRL> show database verbose orcl_st;
Database
Name: orcl_st
Role: PRIMARY
Enabled: YES
Intended State: ONLINE
Instance(s):
orcl
Properties:
InitialConnectIdentifier = 'orcl_st'
LogXptMode = 'SYNC'
Dependency = ''
DelayMins = '0'
Binding = 'OPTIONAL'
MaxFailure = '0'
MaxConnections = '1'
ReopenSecs = '300'
NetTimeout = '30'
LogShipping = 'ON'
PreferredApplyInstance = ''
ApplyInstanceTimeout = '0'
ApplyParallel = 'AUTO'
StandbyFileManagement = 'AUTO'
ArchiveLagTarget = '0'
LogArchiveMaxProcesses = '2'
LogArchiveMinSucceedDest = '1'
DbFileNameConvert = ''
LogFileNameConvert = ''
FastStartFailoverTarget = 'orcl_pd'
StatusReport = '(monitor)'
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
SendQEntries = '(monitor)'
LogXptStatus = '(monitor)'
RecvQEntries = '(monitor)'
HostName = 'dg2'
SidName = 'orcl'
LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.3)(PORT=1521))'
StandbyArchiveLocation = '/u01/archive'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
LatestLog = '(monitor)'
TopWaitEvents = '(monitor)'
Current status for "orcl_st":
Warning: ORA-16817: unsynchronized Fast-Start Failover configuration
DGMGRL> show database verbose orcl_pd;
Database
Name: orcl_pd
Role: PHYSICAL STANDBY
Enabled: NO
Intended State: ONLINE
Instance(s):
orcl
Properties:
InitialConnectIdentifier = 'orcl'
LogXptMode = 'sync'
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 = 'orcl_st'
StatusReport = '(monitor)'
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
SendQEntries = '(monitor)'
LogXptStatus = '(monitor)'
RecvQEntries = '(monitor)'
HostName = 'dg1'
SidName = 'orcl'
LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.2)(PORT=1521))'
StandbyArchiveLocation = 'dgsby_orcl_pd'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
LatestLog = '(monitor)'
TopWaitEvents = '(monitor)'
Current status for "orcl_pd":
Error: ORA-16661: the standby database needs to be reinstated
(3) 将原主库启动到startup mount状态
Broker 需要 SYSDBA 凭证以重新启动两个数据库或其中一个数据库。如果没有该凭证,Broker 仍将完成角色转换,但需要手动重新启动数据库.
将原主库启动到mount状态之后,Observer 会使用当前主库的Flashback Logs,将原来的备库切换到mount状态状态。
恢复的第一步是将数据库闪回到备用数据库变为主数据库的 SCN 处(新主数据库上的 v$database.standby_became_primary_scn)。闪回数据库将分成两个阶段进行:恢复阶段和介质恢复阶段。
在恢复阶段,闪回数据库使用闪回数据库日志中的前映像块将数据库恢复到 standby_became_primary_scn 之前的一点。在介质恢复阶段中,闪回数据库应用重做以将数据库带到standby_became_primary_scn。为使闪回数据库成功,闪回数据库日志中必须包括足够的可用历史记录,并且恢复点和 standby_became_primary_scn 之间生成的所有重做必须可用。如果闪回数据库失败,自动恢复将停止,您将需要手动执行基于 SCN 的恢复以恢复到 standby_became_primary_scn,直到完成该恢复。
一旦闪回数据库成功,观察器会将该数据库转换为备用数据库,执行回弹并开始应用服务。
原主库的log会有如下信息:
[oracle@dg1 bdump]$ D
[oracle@dg1 bdump]$ pwd
/u01/app/oracle/admin/orcl/bdump
[oracle@dg1 bdump]$ ls
alert_orcl.log orcl_arc0_5217.trc orcl_mrp0_5237.trc orcl_nsv1_5173.trc orcl_rsm0_5177.trc
drcorcl.log orcl_arc1_5219.trc orcl_nsv1_5165.trc orcl_pmon_5131.trc orcl_rsm0_5233.trc
[oracle@dg1 bdump]$ tail -100 drcorcl.log
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM REGISTER]
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM REGISTER] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET log_archive_dest_1='location="/u01/archive"', 'valid_for=(ALL_LOGFILES,ALL_ROLES)' scope=both sid='orcl' ]
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET log_archive_dest_1='location="/u01/archive"', 'valid_for=(ALL_LOGFILES,ALL_ROLES)' scope=both sid='orcl' ] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET log_archive_dest_state_1='ENABLE' SCOPE=BOTH sid='orcl']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET log_archive_dest_state_1='ENABLE' SCOPE=BOTH sid='orcl'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET standby_archive_dest='/u01/archive' SCOPE=BOTH sid='orcl']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET standby_archive_dest='/u01/archive' SCOPE=BOTH sid='orcl'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Setting init.ora parameter with SQL [ALTER SYSTEM SET log_archive_trace=0 SCOPE=BOTH sid='orcl']
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET log_archive_trace=0 SCOPE=BOTH sid='orcl']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET log_archive_trace=0 SCOPE=BOTH sid='orcl'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Setting init.ora parameter with SQL [ALTER SYSTEM SET log_archive_format='%t_%s_%r.dbf' SCOPE=SPFILE sid='orcl']
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET log_archive_format='%t_%s_%r.dbf' SCOPE=SPFILE sid='orcl']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET log_archive_format='%t_%s_%r.dbf' SCOPE=SPFILE sid='orcl'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Setting init.ora parameter with SQL [ALTER SYSTEM SET standby_file_management='AUTO' SCOPE=BOTH sid='*']
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET standby_file_management='AUTO' SCOPE=BOTH sid='*']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET standby_file_management='AUTO' SCOPE=BOTH sid='*'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Setting init.ora parameter with SQL [ALTER SYSTEM SET archive_lag_target=0 SCOPE=BOTH sid='*']
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET archive_lag_target=0 SCOPE=BOTH sid='*']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET archive_lag_target=0 SCOPE=BOTH sid='*'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Setting init.ora parameter with SQL [ALTER SYSTEM SET log_archive_max_processes=2 SCOPE=BOTH sid='*']
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET log_archive_max_processes=2 SCOPE=BOTH sid='*']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET log_archive_max_processes=2 SCOPE=BOTH sid='*'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Setting init.ora parameter with SQL [ALTER SYSTEM SET log_archive_min_succeed_dest=1 SCOPE=BOTH sid='*']
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET log_archive_min_succeed_dest=1 SCOPE=BOTH sid='*']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET log_archive_min_succeed_dest=1 SCOPE=BOTH sid='*'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET fal_server='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.3)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl_st_XPT)(SERVER=dedicated)))']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET fal_server='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.3)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl_st_XPT)(SERVER=dedicated)))'] Executed successfully
DG 2010-12-14-01:12:12 0 2 0 Executing SQL [ALTER SYSTEM SET fal_client='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.2)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl_pd_XPT)(INSTANCE_NAME=orcl)(SERVER=dedicated)))']
DG 2010-12-14-01:12:12 0 2 0 SQL [ALTER SYSTEM SET fal_client='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.2)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl_pd_XPT)(INSTANCE_NAME=orcl)(SERVER=dedicated)))'] Executed successfully
(4) 最后验证切换之后的状态
在原备库:
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
READ WRITE PRIMARY
SQL> select fs_failover_status from v$database;
FS_FAILOVER_STATUS
---------------------
SYNCHRONIZED
原主库:
SQL> connect sys/oracle as sysdba;
Connected.
SQL> select open_mode from v$database;
OPEN_MODE
----------
MOUNTED
DGMGRL> show configuration verbose;
Configuration
Name: OrclBroker
Enabled: YES
Protection Mode: MaxAvailability
Fast-Start Failover: ENABLED
Databases:
orcl_pd - Physical standby database
- Fast-Start Failover target
orcl_st - Primary database
Fast-Start Failover
Threshold: 120 seconds
Observer: dg2
Current status for "OrclBroker":
SUCCESS
三. 移除Broker
官网的说明参考:
How to Safely Remove a Data Guard Broker Configuration [ID 261336.1]
http://blog.csdn.net/xujinyang/article/details/6833165
------------------------------------------------------------------------------