【场景一】Oracle11.2.0.4 DG搭建之备节点复制主库
主库:
一:强制force logging: alter database force logging;
二:开启主库的归档模式
三:主库添加standby redo log,比redo日志组多一组:
ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/data/app/oracle/oradata/PROD/redo04_1.log','/data/app/oracle/oradata/PROD/redo04_2.log') size 1024M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/data/app/oracle/oradata/PROD/redo05_1.log','/data/app/oracle/oradata/PROD/redo05_2.log') size 1024M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/data/app/oracle/oradata/PROD/redo06_1.log','/data/app/oracle/oradata/PROD/redo06_2.log') size 1024M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/data/app/oracle/oradata/PROD/redo07_1.log','/data/app/oracle/oradata/PROD/redo07_2.log') size 1024M;
select * from v$standby_log;
四:创建pfile文件
主库初始化参数的配置:注意:内存分配、数据目录、日志目录、DBname主备相同,DB_UNIQUE_NAME主备不同,11g动态注册的监听服务名、数据库的service_names与DB_UNIQUE_NAME一致
PROD.__data_transfer_cache_size=0
PROD.__db_cache_size=2415919104
PROD.__java_pool_size=16777216
PROD.__large_pool_size=33554432
PROD.__oracle_base='/data/oracle/product'#ORACLE_BASE set from environment
PROD.__pga_aggregate_target=1241513984
PROD.__sga_target=6861881344
PROD.__shared_io_pool_size=251658240
PROD.__shared_pool_size=4093640704
PROD.__streams_pool_size=33554432
*.audit_file_dest='/data/app/oracle/admin/PROD/adump'
*.audit_trail='db'
*.compatible='12.1.0.2.0'
*.control_files='/data/app/oracle/oradata/PROD/control01.ctl','/data/app/oracle/fast_recovery_area/PROD/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='PROD'
*.db_recovery_file_dest='/data/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4560m
*.diagnostic_dest='/data/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=PRODXDB)'
#*.log_archive_dest_1='location=/data/app/oracle/archivelog'
*.open_cursors=300
*.pga_aggregate_target=1512m
*.processes=5000
*.local_listener='LISTENER_PROD'
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=7536m
*.undo_tablespace='UNDOTBS1'
DB_UNIQUE_NAME=PROD
LOG_ARCHIVE_CONFIG='DG_CONFIG=(prod,proddg)'
LOG_ARCHIVE_DEST_1= 'LOCATION=/data/app/oracle/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prod'
LOG_ARCHIVE_DEST_2= 'SERVICE=proddg ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=proddg'
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_DEST_1='enable'
LOG_ARCHIVE_DEST_2='enable'
FAL_CLIENT=prod
FAL_SERVER=proddg
DB_FILE_NAME_CONVERT='/data/app/oracle/oradata/PROD/','/data/app/oracle/oradata/PROD/'
#编辑DB_FILE_NAME_CONVERT,特别注意datafile、tempfile、controlfile的目录写全
LOG_FILE_NAME_CONVERT='/data/app/oracle/oradata/PROD/','/data/app/oracle/oradata/PROD/'
STANDBY_FILE_MANAGEMENT=AUTO
五:在主备库创建静态listener和tnsnames.ora,主库创建口令文件,发送到备库
LISTENER= (DESCRIPTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=tcp)(HOST= 10.26.208.131)(PORT=1521)) (ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))) SID_LIST_LISTENER= (SID_LIST= (SID_DESC= (GLOBAL_DBNAME=prod) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1) (SID_NAME=prod) ) ) cat tnsnames.ora prod= (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=10.26.208.130)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=prod)) )
proddg= (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=10.26.208.131)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=prod)) )
口令文件:orapwd file=orapwinstance_name(实例名) password= entries=10 force=y
在主库创建口令文件orapwpdb,然后scp到备库,在备库修改名为orapwsdb
六:在备库修改初始化参数文件pfile
七:对主库进行备份,发送至备库。
在主备库,创建/backup备份目录
对主库进行备份:
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
sql 'alter system archive log current';
backup format '/backup/db_%U_%T' skip inaccessible filesperset 5 database;
sql 'alter system archive log current';
backup format '/backup/db_%U_%T' skip inaccessible filesperset 5 archivelog all delete input;
backup current controlfile for standby format='/backup/control_%U';
release channel c2;
release channel c1;
}
八:主备机器配置双向SSH互信,将主库的备份复制到备库的/backup,相同目录,如果目录不相同,则使用catalog start with '备份所在的路径' 或者 catalog 例如:catalog backuppiece '/node2/database/backup/o1_mf_annnn_TAG20070213T002925_2x21m6ty_.bkp';
scp /backup/* 192.168.9.2:/backup/
九:开启备库至nomount,进行恢复
SQL>startup nomount
在备库进行恢复
$rman target sys/sys@prod auxiliary sys/sys@proddg
RMAN> duplicate target database for standby nofilenamecheck from active database;
#duplicate target database for standby from active database nofilenamecheck; #文件目录相同时使用该命令
#duplicate target database for standby from active database dorecover; #文件目录不相同时使用该命令
注:临时表空间不会复制到备库
十:打开备份,查询状态,可能需要应用归档进行恢复
重建备库的standby redo log(可选)
最后,验证主库
select dest_name,status,process,error,transmit_mode from v$archive_dest where target='STANDBY';
主备切换验证
问题处理:一主五从
ORA-16198: Timeout incurred on internal channel during remote archival
SQL>select dest_name,status,process,error,transmit_mode from v$archive_dest where target='STANDBY';
DEST_NAME STATUS PROCESS ERROR TRANSMIT_MOD
-------------------- --------- ---------- ----------------------------------------------------------------- ------------
LOG_ARCHIVE_DEST_2 ERROR LGWR ORA-16198: Timeout incurred on internal channel during remote ASYNCHRONOUS archival
LOG_ARCHIVE_DEST_3 VALID LGWR PARALLELSYNC
LOG_ARCHIVE_DEST_4 VALID LGWR ASYNCHRONOUS
LOG_ARCHIVE_DEST_5 VALID LGWR PARALLELSYNC
LOG_ARCHIVE_DEST_6 VALID LGWR ASYNCHRONOUS
SQL> alter system set log_archive_dest_2='service=hbhsdb LGWR ASYNC NET_TIMEOUT=40 valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=prod';
SQL>select dest_name,status,process,error,transmit_mode from v$archive_dest where target='STANDBY';
DEST_NAME STATUS PROCESS ERROR TRANSMIT_MOD
-------------------- --------- ---------- ----------------------------------------------------------------- ------------
LOG_ARCHIVE_DEST_2 VALID LGWR ASYNCHRONOUS
LOG_ARCHIVE_DEST_3 VALID LGWR PARALLELSYNC
LOG_ARCHIVE_DEST_4 VALID LGWR ASYNCHRONOUS
LOG_ARCHIVE_DEST_5 VALID LGWR PARALLELSYNC
LOG_ARCHIVE_DEST_6 VALID LGWR ASYNCHRONOUS
ORA-16024: parameter LOG_ARCHIVE_DEST_1 cannot be parsed
在备库启动到nomount,报错ORA-16024
解决方式:在pfile文件注释掉下列两个参数
LOG_ARCHIVE_DEST_1='enable'
LOG_ARCHIVE_DEST_2='enable'