作者 阿九【转载时请务必以超链接形式标明文章原始出处和作者信息】
RAC对单实例数据库的DATAGUARD配置,主要步骤有12步,如下:
1、主库全库备份
备份脚本
$ cat rman_full_20121221.sh
#!/bin/ksh
export ORACLE_HOME=/oracle/db10g
export PATH=$ORACLE_HOME/bin:$PATH
su - oracle -c "rman target / catalog zgdb/zgdb@tsm cmdfile /usr/tivoli/tsm/client/oracle/sched/rman_full_20121221.rcv msglog /usr/tivoli/tsm/client/oracle/sched/rman_full_20121221.log append"
$ cat rman_full_20121221.rcv
run {
allocate channel d1 type disk format '/expdpbak/full_db_20121221_1.dbf';
allocate channel d2 type disk format '/expdpbak/full_db_20121221_2.dbf';
allocate channel d3 type disk format '/expdpbak/full_db_20121221_3.dbf';
allocate channel d4 type disk format '/expdpbak/full_db_20121221_4.dbf';
backup as compressed backupset database tag='FULL_DB_20121221';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
2、创建备数据库控制文件
SQL> alter database create standby controlfile as '/expdpbak/stdb.20121222.ctl';
Database altered.
SQL>
3、备份主库spfile文件
SQL> create pfile='/oracle/dataguard/spfile_preconf_20121222.ora' from spfile;
File created.
SQL>
4、执行备库控制文件恢复
通过pfile文件,修改控制文件位置,指向刚才创建的备库控制文件
使用pfile启动数据库mount状态
#注意:如果主备库文件通过NFS模式来传递,则需要注意相关的文件权限,并在备库上执行如下命令
alter system set events '10298 trace name context forever,level 32';
连接RMAN工具,从刚创建的备库控制文件恢复备库控制文件
run{
allocate channel d1 type disk;
restore standby controlfile to '/dev/rdb_control01';
restore standby controlfile to '/dev/rdb_control02';
restore standby controlfile to '/dev/rdb_control03';
release channel d1;
}
5、更该备库pfile文件中controlfile参数位置,指向正确的控制文件位置,重启数据库
重启完数据库后,如果备份文件是在NFS磁盘上,还需要再此执行命令
alter system set events '10298 trace name context forever,level 32';
6、恢复备库
恢复脚本
$ cat restore_20121222.sh
#!/bin/ksh
ORACLE_BASE=/oracle
ORACLE_HOME=/oracle/app/db10g
rman target / cmdfile /home/oracle/restore_20121222.rcv msglog /home/oracle/restore_20121222.log append
$ cat restore_20121222.rcv
restore database from tag='FULL_DB_20121221';
$
7、添加备库重做日志文件,按线程来加(一般来说,比主库每个线程下的日志组多一个即可,比如我的库有两个线程,每个线程下有4个日志组,因此我只需要加5个备重做日志文件即可,日志文件大小与主库保持一致)
alter database add standby logfile thread 1 ('/dev/rdb_stdredo11') size 500M;
alter database add standby logfile thread 1 ('/dev/rdb_stdredo12') size 500M;
alter database add standby logfile thread 1 ('/dev/rdb_stdredo13') size 500M;
alter database add standby logfile thread 1 ('/dev/rdb_stdredo14') size 500M;
alter database add standby logfile thread 1 ('/dev/rdb_stdredo15') size 500M;
alter database add standby logfile thread 2 ('/dev/rdb_stdredo21') size 500M;
alter database add standby logfile thread 2 ('/dev/rdb_stdredo22') size 500M;
alter database add standby logfile thread 2 ('/dev/rdb_stdredo23') size 500M;
alter database add standby logfile thread 2 ('/dev/rdb_stdredo24') size 500M;
alter database add standby logfile thread 2 ('/dev/rdb_stdredo25') size 500M;
查看备重做日志组信息
select group#,thread#,sequence#,archived,status from v$standby_log;
如果备重做日志添加错误,可以使用如下命令删除备重做日志
alter database drop standby logfile ('/dev/rdb_stdredo11');
8、配置监听
在$ORACLE_HOME/network/admin/tnsnames.ora文件中加入备库的TSN
9、配置主库参数
注意:如果RAC各个实例使用自己的spfile文件,则这些参数都需要在各个实例上配置。包括SID='*'的参数
alter system set log_archive_config='DG_CONFIG=(zgdb,zgstdby)' scope=both sid='*';
alter system set log_archive_dest='' scope=both sid='zgdb1';
alter system set log_archive_dest_1='LOCATION=/archive1 valid_for=(all_logfiles,all_roles) db_unique_name=zgdb' scope=both sid='zgdb1';
alter system reset log_archive_dest scope=spfile sid='zgdb1';
alter system set log_archive_dest='' scope=both sid='zgdb2';
alter system set log_archive_dest_1='LOCATION=/archive2 valid_for=(all_logfiles,all_roles) db_unique_name=zgdb' scope=both sid='zgdb2';
alter system reset log_archive_dest scope=spfile sid='zgdb2';
alter system set log_archive_dest_2='service=zgstdby lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=zgstdby' scope=both sid='*';
alter system set log_archive_dest_state_1='ENABLE' scope=both sid='*';
alter system set log_archive_dest_state_2='ENABLE' scope=both sid='*';
10、配置备库参数
alter system set log_archive_config='DG_CONFIG=(zgdb,zgstdby)' scope=both sid='*';
alter system set log_archive_dest_1='LOCATION=/archive1 valid_for=(all_logfiles,all_roles) db_unique_name=zgstdby' scope=both sid='*';
alter system et log_archive_dest_2='service=zgdb lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=zgdb' scope=both sid='*';
alter system set log_archive_dest_state_1='ENABLE' scope=both sid='*';
alter system set log_archive_dest_state_2='ENABLE' scope=both sid='*';
11、启动重做应用
alter database recover managed standby database disconnect from session;
可以使用如下命令停止重做应用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
12、在备库上注册从主库上传送过来的归档日志文件
一般默认下,配置好参数,启动备库重做应用后,归档日志会自动传送过来。
如果没有传送过来,可以使用ftp下载到备库的归档目录下。
当下载完归档后还不能应用归档,则使用下面的命令去注册归档文件:
alter database register logfile '/archive1/1_100000_627955761.dbf';
13、确认现有的重做日志文件
select sequence#,first_time,next_time from v$archived_log order by sequence#;
14、检查新归档的重做日志问价已应用
select sequence#,applied from v$archived_log order by sequence#;
15、完成后的检查
select sequence#,first_time,next_time,applied from v$archived_log order by sequence#;
16、查看是否有未传输的文件
select * from v$archive_gap;