首页 > 代码库 > [terry笔记]11gR2_DataGuard搭建_拷贝数据文件

[terry笔记]11gR2_DataGuard搭建_拷贝数据文件

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 logfilegroup 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 immeidatestartup

 

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/dbsstandby控制文件: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=222298112good.__java_pool_size=4194304good.__large_pool_size=8388608good.__oracle_base=/u01#ORACLE_BASE set from environmentgood.__pga_aggregate_target=192937984good.__sga_target=360710144good.__shared_io_pool_size=0good.__shared_pool_size=113246208good.__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 sysdbasqlplus sys/xxx@bad as sysdbatnsping goodtnsping 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