listener.ora设置
l_dg=
(address=
(protocol=tcp)(host=orainst.desktop.mycompany.com)(port=8000)(queuesize=32)
)
log_file_l_torcla_001=/tmp/l_torclb_001.log
sid_list_l_dg=
(sid_list =
(sid_desc=
(oracle_home=/data1/dg/10.2.0.2/a10db)
(sid_name=torcl)
)
本地tnsname.ora的设置
torcl.mycompany=
(description=
(enable=broken)
(address_list=
(address=(protocol=tcp)(host=orainst.desktop.mycompany.com)(port=8000))
)
(connect_data=
(sid=torcl)
)
torcla.mycompany=
(sdu= 32767)
(service_name=torcla.mycompany)
(server=dedicated)
torclb.mycompany=
(service_name=torclb.mycompany)
dg的相关设置
-- 保护模式
sys@torclb> select database_role, protection_mode, open_mode, switchover_statusfrom v$database;
database_role protection_mode open_mode switchover_status
-------------------- ------------------------- --------------- --------------------
primary maximum performance readwrite sessions active
-- 日志归档相关设置
sys@torclb> show parameter log_archive_dest_1
name type value
------------------------------------ --------------------------------- ------------------------------
log_archive_dest_1 string location="/data1/dg/databases/
torclb/redolog", valid_for=(onl
ine_logfile,all_roles)
sys@torclb> show parameter log_archive_dest_2
log_archive_dest_1 string service=torcla.mycompanyvalid_fo
tr=(online_logfile, primary_ro
tle)reopen=60optionallgwrs
tyncaffirmdb_unique_name=torcla
下面按照上一篇文章所列出的准备工作清单一一做一遍。
不管是primary数据库还是standby数据库都要完成这一步,设置完毕后重启下数据库使设置生效。
--在当前的primary上
sys@torclb> create spfile='/data1/dg/10.2.0.2/a10db/dbs/spfiletorclb.ora' from pfile;
file created.
--在当前的standby上
sys@torcla> create spfile='/data1/dg/10.2.0.2/a10db/dbs/spfiletorclb.ora' from pfile;
然后修改init文件设定spfile参数:
-- primary的init文件
$cat inittorclb.ora
spfile='spfiletorclb.ora'
-- standby的init文件
$cat inittorcla.ora
spfile='spfiletorcla.ora'
配置dg_broker_config_filen
这里我们的dg_broker_config_filen不做特别的设置,使用默认的$oracle_home/dbs目录以及两个默认的文件名dr1.dat和dr2.dat。
当然也可以用sqlplus通过下面语句设定不同的目录,要注意在两个数据库上面都要设置:
alter system set dg_broker_config_file1='/data1/dg/10.2.0.2/a10db/dbs/dr1torcla.dat';
alter system set dg_broker_config_file2='/data1/dg/10.2.0.2/a10db/dbs/dr2torcla.dat'
设置local_listener
这一步设置是为了保证一些service name能正确的被注册上。
sys@torcla> alter system set local_listener='(description=(address=(protocol=tcp)(host=orainst.desktop.mycompany.com)(port=8000)))' scope=both;
system altered.
在当前的测试环境中primary和standby是在同一机器上面,因此这个service name的设置也是在同一个listener.ora文件上,设置完了以后的listener.ora如下
(sid_desc=
(sid_name=torcla)
(global_dbname=torcla_dgmgrl.mycompany)
(sid_name=torclb)
(global_dbname=torclb_dgmgrl.mycompany)
设置tnsmaes.ora
torcla_dgmgrl.mycompany =
(description=
(address= (protocol = tcp)(host = orainst.desktop.mycompany.com)(port = 8000))
(connect_data=
(service_name=torcla_dgmgrl.mycompany)))
torclb_dgmgrl.mycompany =
(service_name=torclb_dgmgrl.mycompany)))
设置完毕后记得重启下listener,然后查看一下设置的效果:
oracle@orainst[torcla]:~
$lsnrctlservicel_dg|grep'service '
service "torcl" has 1 instance(s).
service "torcla.mycompany" has 1 instance(s).
service "torcla_dgmgrl.mycompany" has 1 instance(s).
service "torcla_xpt.mycompany" has 1 instance(s).
service "torclb.mycompany" has 1 instance(s).
service "torclb_dgmgrl.mycompany" has 1 instance(s).
service "torclb_xpt.mycompany" has 1 instance(s).
从上面的listener上注册的服务我们可以看到动态注册的_xpt已经有了,说明local_listener设置正确,_dgmgrl也配置正确。
这一步是启动data guard broker monitor(dmon)进程,在两个数据库上面都运行下下面的命令
alter system set dg_broker_start=true scope=both;
然后查看下结果,先看进程是否起来了
$ps -ef|grepdmon|grep -vgrep
oracle 19389 1 009:51 ? 00:00:00ora_dmon_torcla
oracle 19420 1 009:51 ? 00:00:00ora_dmon_torclb
可以看到两个dmon进程都起来了,接下来看看service name _dgb有没有被正确的注册上
$lsnrctl service l_dg| grep 'service '
service "torcl" has 1 instance(s).
service "torcla_dgb.mycompany" has 1 instance(s).
service "torclb_dgb.mycompany" has 1 instance(s).
可以看到service name _dgb也正常的注册上了,到现在我们前期的准备工就已经全部完成了。
现在我们可以来配置broker了,为了保证配置过程不会因为权限问题导致问题,我们始终都是用sys连接数据库的。
首先使用dgmgrl连接到primary机器上,运行下面的命令:
$dgmgrl sys/[email protected]
dgmgrl for linux: version10.2.0.2.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 can not be determined by dgmgrl
当前还没有任何的配置信息,现在创建一个配置
dgmgrl> create configuration 'fsf' as
> primary database is 'torclb'
> connect identifier is torclb.mycompany;
configuration "fsf" created with primary database "torclb"
这样我们就创建了一个名为fsf的broker配置,接下来把standby机器也就入到配置中
dgmgrl> add database 'torcla' as
> connect identifier is torcla.mycompany
> maintained as physical;
database "torcla" added
就这两步,broker的最基本配置就完成了,这下可以用show configuration来看成果了。
configuration
name: fsf
enabled: no
protectionmode: maxperformance
fast-start failover: disabled
databases:
torclb - primary database
torcla - physical standby database
current status for "fsf":
disabled
可以看到torclb是primary数据库,而torcla是physical standby数据库,不过这是的broker配置的状态是禁用的,说明我们的两个数据库是没有被broker管理的,只是加入到了broker配置中了而已,接下来启用一下。
dgmgrl> enable configuration
enabled.
enabled: yes
success
这样就成了,一个成功的broker配置完成,挺简单的。
最后我们做一个switchover来检验下成果吧,具体的switchover的过程在后面再介绍。
dgmgrl> switchover to torcla
performing switchover now, please wait...
operation requires shutdown of instance "torclb" on database "torclb"
shutting down instance "torclb"...
ora-01109: database not open
database dismounted.
oracle instance shutdown.
operation requires shutdown of instance "torcla" on database "torcla"
shutting down instance "torcla"...
operation requires startup of instance "torclb" on database "torclb"
starting instance "torclb"...
oracle instance started.
database mounted.
operation requires startup of instance "torcla" on database "torcla"
starting instance "torcla"...
switchover succeeded, new primary is "torcla"
torclb - physical standby database
torcla - primary database
我们已经成功的将primary数据库却换成了torcla,用一个简单的命令,这个就是broker的优势所在,简单!
参考至:http://www.dbabeta.com/2009/learn-data-guard-broker_a-broker-example.html
如有错误,欢迎指正
作者:czmmiao 文章出处:http://czmmiao.iteye.com/blog/2124742