11gR2搭建dataguard環境:
自己做的實驗,後續按照rman模式搭建、主備切換、模式調整等實驗會陸續發上來。
primary:
OS:oel 6.4
database:11.2.0.4.0
192.168.100.131
hostname=node4
ORACLE_SID=good
ORACLE_HOME=/u01/product/11.2.0
db_unique_name=good
standby:
OS:oel 6.4
database:11.2.0.4.0
192.168.100.132
ORACLE_SID=good
ORACLE_HOME=/u01/product/11.2.0
db_unique_name=bad
兩邊oracle用戶的環境變量:
export ORACLE_BASE=/u01
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0
export ORACLE_SID=good
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
alias s='sqlplus / as sysdba'
1.primary打開force logging和歸檔:
alter database force logging; startup mount; alter database archivelog; alter database open;
2.配置primary參數,並添加standby logfile,以用來將來主備切換
alter system set db_unique_name=good scope=spfile; alter system set log_archive_config= 'DG_CONFIG=(good,bad)' scope=spfile; alter system set log_archive_dest_1= 'LOCATION=/u01/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=good' scope=spfile; alter system set log_archive_dest_2= 'SERVICE=bad LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=bad' scope=spfile; alter system set log_archive_dest_state_1 = enable; alter system set log_archive_dest_state_2 = enable; alter system set fal_server=bad scope=spfile; alter system set fal_client=good scope=spfile; alter system set standby_file_management=AUTO scope=spfile;
alter database add standby logfile group 4 ('/u01/oradata/good/standby04.log')size 50m, group 5 ('/u01/oradata/good/standby05.log')size 50m, group 6 ('/u01/oradata/good/standby06.log')size 50m, group 7 ('/u01/oradata/good/standby07.log')size 50m;
3.重啟一次驗證以上修改沒問題:
shutdown immeidate startup
4.創建standby controlfile、pfile
alter database create standby controlfile as '/u01/control01.ctl'; create pfile from spfile;
5.關閉primary
shutdown immediate
6.配置primary的listener.ora、tnsname.ora,listner要用靜態監聽,傳到standby時注意修改host
# listener.ora Network Configuration File: /u01/product/11.2.0/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /u01/product/11.2.0) (PROGRAM = extproc) ) (SID_DESC = (GLOBAL_DBNAME = good) (ORACLE_HOME = /u01/product/11.2.0) (SID_NAME = good) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01
# tnsnames.ora Network Configuration File: /u01/product/11.2.0/network/admin/tnsnames.ora # Generated by Oracle configuration tools. GOOD = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.131)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = good) ) ) BAD = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.132)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = good) ) )
7.copy file to standby
監聽文件:listener.ora、tnsnames.ora --$ORACLE_HOME/network/admin 參數文件:initgood.ora --$ORACLE_HOME/dbs 密碼文件:orapwgood --$ORACLE_HOME/dbs standby控制文件:control01.ctl --$ORACLE_BASE/oradata/good 全庫備份文件:*.dbf、*.log --$ORACLE_BASE/oradata/good 日志目錄(或直接創建文件夾):$ORACLE_BASE/admin、$ORACLE_BASE/diag、$ORACLE_BASE/flash_recovery_area
8.修改standby參數文件,藍色標注的需要重點關注
good.__db_cache_size=222298112 good.__java_pool_size=4194304 good.__large_pool_size=8388608 good.__oracle_base='/u01'#ORACLE_BASE set from environment good.__pga_aggregate_target=192937984 good.__sga_target=360710144 good.__shared_io_pool_size=0 good.__shared_pool_size=113246208 good.__streams_pool_size=0 *.audit_file_dest='/u01/admin/good/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/u01/oradata/good/control01.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='good' *.db_recovery_file_dest='/u01/fast_recovery_area' *.db_recovery_file_dest_size=4385144832 *.db_unique_name='bad' *.diagnostic_dest='/u01' *.dispatchers='(PROTOCOL=TCP) (SERVICE=goodXDB)' *.fal_client='bad' *.fal_server='good' *.log_archive_config='dg_config=(good,bad)' *.log_archive_dest_1='location=/u01/arch valid_for=(all_logfiles,all_roles) db_unique_name=bad' *.log_archive_dest_2='service=good lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=good' *.log_archive_dest_state_1='ENABLE' *.log_archive_dest_state_2='ENABLE' *.memory_target=550502400 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.standby_file_management='AUTO' *.undo_tablespace='UNDOTBS1'
9.啟動兩邊監聽
lsnrctl start 此時可以測試兩邊是否連通 sqlplus sys/xxx@good as sysdba sqlplus sys/xxx@bad as sysdba tnsping good tnsping bad
select * from v$instance;
10.standby啟動至mount並應用日志
startup mount; alter database recover managed standby database using current logfile disconnect from session;
11.primary啟動
startup
12.驗證
觀察primary與standby的/u01/arch,當primary切換時,standby的歸檔也會增加。 primary:
alter system switch logfile; SELECT STATUS,DESTINATION, ERROR FROM V$ARCHIVE_DEST; select max(sequence#) from v$archived_log; --主備結果一致
13.standby啟動read only with apply,此時可以查詢standby庫同時可以從primary恢復(此為11g特性,10g如果read only打開standby庫,不可以同時恢復)
alter database recover managed standby database cancel; alter database open; alter database recover managed standby database using current logfile disconnect from session; select open_mode from v$database;
dataguard啟動與關閉順序:
啟動:先standby後primary
關閉:先primary後standby