在Oracle数据库日常运维中往往会碰到这种情况:DataGuard主库归档删了,备库由于缺少归档从而GAP报错,此时经常的做法是重新拉数据,如果数据量小还好,数据量TB级别了在加之网络带宽有限,这明显不是一个很好的解决方案,本文分享基于备库的最小SCN在主库做增量备份的方法修复DG。
- 备库查询最小SCN
SQL> select min(f.fhscn) from x$kcvfh f, v$datafile d where f.hxfil =d.file# and d.enabled != 'READ ONLY';
MIN(F.FHSCN)
----------------
16471785731987
这里的16471785731987就是备库的最小SCN。
2. 在主库基于最小SCN做增量备份
[oracle@ray01 shrman]$ vi shrman20200623.sh
source /home/oracle/.bash_profile
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
rman target / log /shrman/shrman/shrman20200623.log <<EOF
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
backup as compressed backupset INCREMENTAL FROM SCN 16471785731987 database format "/shrman/shrman/incre_%d_%T_%s";
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
}
[oracle@ray01 shrman]$ nohup ./shrman20200623.sh &
- 将备份集从主库传输至备库
由于本文中我采用的是NFS挂在,直接就备份在远端了,小伙伴们可以使用FTP、SCP等方式将备份集传输至备库上。 - 备库注册备份集
[oracle@raydg shrman]$ rman target /
RMAN> catalog start with '/backup/rman';
- 恢复备份集
RMAN> recover database noredo;
- 重新同步控制standby controlfile
[oracle@ray01 shrman]$ sqlplus / as sysdba
SQL> alter database create standby controlfile as '/shrman/shrman/dg.ctl';
- 传输standby controlfile至备库
- 重启数据库
- 开启MRP