Data Guard Broker系列之二:Data Guard Broker配置實戰

fanhongjie發表於2010-12-29

轉自:


[@more@]
配置之前DG環境狀態

測試的DG環境安裝在同一個機器上,當前兩個資料庫處於同步的狀態,兩個例項的名字分別是TORCLA和TORCLB,資料庫的名字TORCL,資料庫DB_DOMAIN設定為mycompany,其他的設定如下。

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.logSID_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=
(DESCRIPTION
=
(SDU= 32767)

(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=orainst.desktop.mycompany.com)(PORT=8000))

(ADDRESS=(PROTOCOL=TCP)(HOST=orainst.desktop.mycompany.com)(PORT=8000))
)
(CONNECT_DATA=
(SERVICE_NAME=torcla.mycompany)

(SERVER=DEDICATED)
)
)
torclb.mycompany=
(DESCRIPTION
=
(SDU= 32767)

(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=orainst.desktop.mycompany.com)(PORT=8000))

(ADDRESS=(PROTOCOL=TCP)(HOST=orainst.desktop.mycompany.com)(PORT=8000))
)
(CONNECT_DATA=
(SERVICE_NAME=torclb.mycompany)

(SERVER=DEDICATED)
)
)

DG的相關設定

-- 保護模式SYS@torclb> SELECT DATABASE_ROLE, PROTECTION_MODE, OPEN_MODE, SWITCHOVER_STATUS FROM V$DATABASE;DATABASE_ROLE PROTECTION_MODE OPEN_MODE SWITCHOVER_STATUS
------------------
-- ------------------------- --------------- --------------------primary MAXIMUM PERFORMANCE READ WRITE SESSIONS ACTIVE
-- 日誌歸檔相關設定SYS@torclb> show parameter log_archive_dest_1NAME 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_2NAME TYPE VALUE
----------------------------------
-- --------------------------------- ------------------------------log_archive_dest_1 string SERVICE=torcla.mycompany valid_fo
tr=(online_logfile, primary_ro
tle) REOPEN=60 OPTIONAL LGWR S
tYNC AFFIRM db_unique_name=torcla


topbroker設定準備工作

下面按照上一篇文章所列出的準備工作清單一一做一遍。


top設定primary和standby使用spfile

不管是primary資料庫還是standby資料庫都要完成這一步,設定完畢後重啟下資料庫使設定生效。

--在當前的primarySYS@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;
File created.

然後修改init檔案設定spfile引數:

-- primary的init檔案
$
cat inittorclb.oraspfile='spfiletorclb.ora'
-- standby的init檔案
$
cat inittorcla.oraspfile='spfiletorcla.ora'


top配置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'


top設定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.


top新增靜態的_unique_name_DGMGRL.db_domain註冊

在當前的測試環境中primary和standby是在同一機器上面,因此這個service name的設定也是在同一個listener.ora檔案上,設定完了以後的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.logSID_LIST_L_dg=
(SID_LIST
=
(SID_DESC
=
(ORACLE_HOME=/data1/dg/10.2.0.2/A10db)

(SID_NAME=torcl)
)
(SID_DESC=
(ORACLE_HOME=/data1/dg/10.2.0.2/A10db)

(SID_NAME=torcla)
(GLOBAL_DBNAME=torcla_DGMGRL.mycompany)
)
(SID_DESC=
(ORACLE_HOME=/data1/dg/10.2.0.2/A10db)

(SID_NAME=torclb)
(GLOBAL_DBNAME=torclb_DGMGRL.mycompany)
)
)

設定完畢後記得重啟下listener,然後檢視一下設定的效果:

oracle@orainst[torcla]:~
$
lsnrctl service L_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也配置正確。


top設定dg_broker_start為TRUE

這一步是啟動Data Guard broker monitor(DMON)程式,在兩個資料庫上面都執行下下面的命令

alter system set dg_broker_start=true scope=both;

然後檢視下結果,先看程式是否起來了

oracle@orainst[torcla]:~
$
ps -ef|grep dmon|grep -v grep
oracle 19389 1 0 09:51 ? 00:00:00 ora_dmon_torclaoracle 19420 1 0 09:51 ? 00:00:00 ora_dmon_torclb

可以看到兩個dmon程式都起來了,接下來看看service name _DGB有沒有被正確的註冊上

oracle@orainst[torcla]:~
$
lsnrctl service L_dg|grep 'Service '
Service "torcl" has 1 instance(s).Service "torcla.mycompany" has 1 instance(s).Service "torcla_DGB.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_DGB.mycompany" has 1 instance(s).Service "torclb_DGMGRL.mycompany" has 1 instance(s).Service "torclb_XPT.mycompany" has 1 instance(s).

可以看到service name _DGB也正常的註冊上了,到現在我們前期的準備工就已經全部完成了。


top配置broker

現在我們可以來配置broker了,為了保證配置過程不會因為許可權問題導致問題,我們始終都是用sys連線資料庫的。

首先使用DGMGRL連線到primary機器上,執行下面的命令:

oracle@orainst[torcla]:~
$
dgmgrl sys/12345@torclb.mycompany
DGMGRL for Linux: Version 10.2.0.2.0 - Production
Copyright (c) 2000, 2005, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information
.Connected.DGMGRL> show configurationError: ORA-16532: Data Guard broker configuration does not exist
Configuration details cannot be determined by DGMGRLDGMGRL>

當前還沒有任何的配置資訊,現在建立一個配置

DGMGRL> create configuration 'FSF' as
>
primary database is 'torclb'
>
connect identifier is torclb.mycompany;Configuration "FSF" created with primary database "torclb"DGMGRL>

這樣我們就建立了一個名為FSF的broker配置,接下來把standby機器也就入到配置中

DGMGRL> add database 'torcla' as
>
connect identifier is torcla.mycompany
>
maintained as physical;Database "torcla" addedDGMGRL>

就這兩步,broker的最基本配置就完成了,這下可以用show configuration來看成果了。

DGMGRL> show configuration
Configuration
Name: FSF
Enabled: NO
Protection Mode: MaxPerformance
Fast-Start Failover: DISABLED
Databases:
torclb - primary database

torcla - Physical standby database
Current status for "FSF":DISABLED
DGMGRL>

可以看到torclb是primary資料庫,而torcla是physical standby資料庫,不過這是的broker配置的狀態是禁用的,說明我們的兩個資料庫是沒有被broker管理的,只是加入到了broker配置中了而已,接下來啟用一下。

DGMGRL> enable configurationEnabled.DGMGRL> show configuration
Configuration
Name: FSF
Enabled: YES
Protection Mode: MaxPerformance
Fast-Start Failover: DISABLED
Databases:
torclb - primary database

torcla - Physical standby database
Current status for "FSF":SUCCESS

這樣就成了,一個成功的broker配置完成,挺簡單的。

最後我們做一個switchover來檢驗下成果吧,具體的switchover的過程在後面再介紹。

DGMGRL> switchover to torclaPerforming 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 shut down.Operation requires shutdown of instance "torcla" on database "torcla"Shutting down instance "torcla"...ORA-01109: database not open
Database dismounted.ORACLE instance shut down.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"...ORACLE instance started.Database mounted.Switchover succeeded, new primary is "torcla"DGMGRL> show configuration
Configuration
Name: FSF
Enabled: YES
Protection Mode: MaxPerformance
Fast-Start Failover: DISABLED
Databases:
torclb - Physical standby database

torcla - Primary database
Current status for "FSF":SUCCESS
DGMGRL>

我們已經成功的將primary資料庫卻換成了torcla,用一個簡單的命令,這個就是broker的優勢所在,簡單!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/73920/viewspace-1043818/,如需轉載,請註明出處,否則將追究法律責任。

相關文章