前面我们有讲到Oracle 11G DataGuard的搭建,10G的搭建也是大同小异.不过Oracle 10G不支持Standby open
环境:
角色 | 主机名 | IP | 数据库版本 | 操作系统版本 |
Primary | fdb1 | 192.168.10.8 | 10.2.0.1 | CentOS 5.11 x86_64 |
Standby | fdb2 | 192.168.10.9 | 10.2.0.1 | CentOS 5.11 x86_64 |
在fdb1的/etc/hosts中加入(fdb1)
127.0.0.1fdb1 192.168.10.9fdb2
在fdb2的/etc/hosts中加入(fdb2)
127.0.0.1fdb2 192.168.10.8fdb1
创建必要的目录(fdb1,fdb2)
mkdir-p/opt/oracle/flash_recovery_area mkdir-p/opt/oracle/admin/fengdb/{a,b,c,u}dump mkdir/opt/oracle/oradata/fengdb-p mkdir-p/opt/oracle/dbackup mkdir-p/opt/oracle/flash_recovery_area/fengdb/archivelog
查看当前的redo组(fdb1)
selectgroup#,memberfromv$logfile; //增加standby日志组 alterdatabaseaddstandbylogfile('/opt/oracle/oradata/fengdb/standby04.log')size50m; alterdatabaseaddstandbylogfile('/opt/oracle/oradata/fengdb/standby05.log')size50m; alterdatabaseaddstandbylogfile('/opt/oracle/oradata/fengdb/standby06.log')size50m; alterdatabaseaddstandbylogfile('/opt/oracle/oradata/fengdb/standby07.log')size50m;
创建原始参数文件用于备份(fdb1)
createpfile='/tmp/fengdb.pfile.ori'fromspfile;
修改相关参数用于DataGuard环境,注意此处与Oracle 11G不同(fdb1)
altersystemsetdb_unique_name=fdb1scope=spfile; altersystemsetlog_archive_config='dg_config=(fdb1,fdb2)'scope=spfile; altersystemsetlog_archive_dest_1='location=/opt/oracle/flash_recovery_area/fengdb/archivelogvalid_for=(all_logfiles,all_roles)db_unique_name=fdb1'scope=spfile; altersystemsetlog_archive_dest_2='service=fdb2asyncvalid_for=(online_logfiles,primary_role)db_unique_name=fdb2'scope=spfile; altersystemsetlog_archive_dest=''scope=spfile; altersystemsetlog_archive_dest_state_1=enablescope=spfile; altersystemsetlog_archive_dest_state_2=enablescope=spfile; altersystemsetstandby_file_management=autoscope=spfile; altersystemsetfal_server=fdb2scope=spfile; altersystemsetfal_client=fdb1scope=spfile; altersystemsetdb_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area'scope=spfile; altersystemsetlog_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area'scope=spfile;
注意:与Oracle 11G不同的地方有: alter system set log_archive_dest='' scope=spfile; 否则可能出现ORA-16019: cannot use LOG_ARCHIVE_DEST_1 with LOG_ARCHIVE_DEST or LOG_ARCHIVE_DUPLEX_DEST scope=spfile |
执行上面的语句其实就是改了下面的一些参数
*.db_unique_name='fdb1' *.log_archive_config='dg_config=(fdb1,fdb2)' *.log_archive_dest_1='location=/opt/oracle/flash_recovery_area/fengdb/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=fdb1' *.log_archive_dest_2='service=fdb2 async valid_for=(online_logfiles,primary_role) db_unique_name=fdb2' *.log_archive_dest_state_1='ENABLE' *.log_archive_dest_state_2='ENABLE' *.standby_file_management='AUTO' *.fal_client='fdb1' *.fal_server='fdb2' *.db_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area' *.log_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area' *.log_archive_dest='' |
shutdownimmediate startup
修改监听(fdb1)
vim $ORACLE_HOME/network/admin/tnsnames.ora
fdb1= (DESCRIPTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=TCP)(HOST=fdb1)(PORT=1521)) ) (CONNECT_DATA= (SERVER=DEDICATED) (SERVICE_NAME=fdb1) ) ) fdb2= (DESCRIPTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=TCP)(HOST=fdb2)(PORT=1521)) ) (CONNECT_DATA= (SERVER=DEDICATED) (SERVICE_NAME=fdb2) ) )
RMAN备份(fdb1)
rmantarget/ run{ allocatechannelc1typedisk; backupformat'/opt/oracle/dbackup/fengdb_%T_%s_%p'database; sql'altersystemarchivelogcurrent'; backupformat'/opt/oracle/dbackup/archive_log_%T_%s_%p'archivelogall; backupspfileformat'/opt/oracle/dbackup/spfile_%u_%T.bak'; releasechannelc1; } copycurrentcontrolfileforstandbyto'/opt/oracle/dbackup/standby.ctl';
scp -r /opt/oracle/dbackup/* fdb2:/opt/oracle/dbackup
scp -r $ORACLE_HOME/network/admin/*fdb2:$ORACLE_HOME/network/admin/
scp -r$ORACLE_HOME/dbs/* fdb2:$ORACLE_HOME/dbs/
在fdb2上执行如下对数据库进行恢复(fdb2)
RMAN> startup nomount;
RMAN> restore spfile to pfile '/tmp/fengdb.pfile' from '/opt/oracle/dbackup/spfile_rmrioont_20161019.bak';
RMAN> shutdown immediate;
然后修改/etc/fengdb.pfile成如下的红色部分
*.db_unique_name='fdb2'
*.fal_client='fdb2'
*.fal_server='fdb1'
*.log_archive_config='dg_config=(fdb2,fdb1)'
*.log_archive_dest_1='location=/opt/oracle/flash_recovery_area/fengdb/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=fdb2'
*.log_archive_dest_2='service=fdb1 async valid_for=(online_logfiles,primary_role) db_unique_name=fdb1'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
备库复制控制文件(fdb2)
cp /opt/oracle/dbackup/standby.ctl /opt/oracle/oradata/fengdb/control01.ctl
cp /opt/oracle/dbackup/standby.ctl /opt/oracle/oradata/fengdb/control02.ctl
cp /opt/oracle/dbackup/standby.ctl /opt/oracle/oradata/fengdb/control03.ctl
启动至mount状态进行数据的恢复
RMAN>startupmount; RMAN>restoredatabase;
启动备库应用日志
sql>alterdatabaserecovermanagedstandbydatabaseusingcurrentlogfiledisconnectfromsession;
创建参数文件
sql>createspfilefrompfile='/tmp/fengdb.pfile';
注意:Oracle 10G与11G的区别: 10G备库只能启动到mount状态,而11G可以启动到open read only. |
检查日志是否同步(fdb1,fdb2)
selectsequence#,appliedfromv$archived_log;
也可以试着切换下日志
//切换日志 altersystemswitchlogfile; selectsequence#,appliedfromv$archived_log;
在主库:(fdb1)
selectdest_name,status,errorfromv$archive_dest; altersystemsetlog_archive_dest_state_2=enable;
查询角色(fdb1,fdb2)
selectopen_mode,database_rolefromv$database;
如果在备库上
sql> select sequence#,applied from v$archived_log;
no rows selected
而且监听都是正常的,则有可能就是密码没复制过来
保持主库密码和备库密码一致
复制密码文件(fdb1)
scp$ORACLE_HOME/dbs/orapw$ORACLE_SIDfdb2:$ORACLE_HOME/dbs/orapw$ORACLE_SID原文链接:https://www.f2er.com/oracle/212149.html