Heim >Datenbank >MySQL-Tutorial >【Oracle】基于SCN的增量备份修复DataGuard GAP
1. 首先来模拟 Gap 的产生 1.1. 备库关闭: SYS@dgtest_sshutdown immediate; 1.2. 主库切换日志 SYS@dgtestselect SEQUENCE#,ARCHIVED,STATUS from v$log; SEQUENCE# ARC STATUS ---------- --- ---------------- 61 YES ACTIVE 62 YES ACTIVE 63 NO CURREN
SYS@dgtest_s>shutdown immediate;
SYS@dgtest>select SEQUENCE#,ARCHIVED,STATUS from v$log;
SEQUENCE# ARC STATUS
---------- --- ----------------
61 YES ACTIVE
62 YES ACTIVE
63 NO CURRENT
SYS@dgtest>alter system archive log current;
System altered.
SYS@dgtest>select SEQUENCE#,ARCHIVED,STATUS from v$log;
SEQUENCE# ARC STATUS
---------- --- ----------------
64 NO CURRENT
62 YES ACTIVE
63 YES ACTIVE
刚才current的日志已经归档
现在删除63号归档
[oracle@primary arch]$ mv 1_63_909786801.dbf 1_63_909786801.dbf.bak
SYS@dgtest_s>startup
Media Recovery Log /u01/app/oracle/arch/1_62_909786801.dbf
Media Recovery Waiting for thread 1 sequence 63
Fetching gap sequence in thread 1, gap sequence 63-63
Fri May 06 05:28:09 2016
FAL[client]: Failed to request gap sequence
GAP - thread 1 sequence 63-63
DBID 3866310445 branch 909786801
FAL[client]: All defined FAL servers have been attempted.
------------------------------------------------------------
Check that the CONTROL_FILE_RECORD_KEEP_TIME initialization
parameter is defined to a value that's sufficiently large
enough to maintain adequate log switch information to resolve
archivelog gaps.
------------------------------------------------------------
SYS@dgtest>SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
--------------------
UNRESOLVABLE GAP
为UNRESOLVABLE GAP,说明此时的GAP需要我们自己手工去修复,无法自动修复,可自动修复的GAP显示为RESOLVABLE GAP
SYS@dgtest_s>select current_scn from v$database;
CURRENT_SCN
-----------
2567388
RMAN> BACKUP INCREMENTAL FROM SCN 2567388 DATABASE FORMAT '/u01/app/oracle/oradata/tmp/ora11_scn_%U' tag 'For Standby Gap';
[oracle@primary tmp]$ scp * standby:/u01/app/oracle/oradata/tmp
oracle@standby's password:
ora11_scn_0kr54hvk_1_1 100% 125MB 125.2MB/s 00:01
ora11_scn_0lr54l99_1_1 100% 9664KB 9.4MB/s 00:00
SYS@dgtest_s>shutdown immediate;
SYS@dgtest_s>startup mount;
SYS@dgtest_s>alter database recover managed standby database cancel;
RMAN> CATALOG START WITH '/u01/app/oracle/oradata/tmp';
RMAN> recover database noredo;
恢复完毕,这时我们可以观察备库的alert日志:
Incremental restore complete of datafile 4 /u01/app/oracle/oradata/dgtest_s/users01.dbf
checkpoint is 2893208
last deallocation scn is 3
Incremental restore complete of datafile 3 /u01/app/oracle/oradata/dgtest_s/undotbs01.dbf
checkpoint is 2893208
last deallocation scn is 973300
Incremental restore complete of datafile 5 /u01/app/oracle/oradata/dgtest_s/example01.dbf
checkpoint is 2893208
last deallocation scn is 942056
Mon May 09 05:20:25 2016
Incremental restore complete of datafile 2 /u01/app/oracle/oradata/dgtest_s/sysaux01.dbf
checkpoint is 2893208
last deallocation scn is 956093
Incremental restore complete of datafile 1 /u01/app/oracle/oradata/dgtest_s/system01.dbf
checkpoint is 2893208
last deallocation scn is 955346
发现数据文件的scn号都已经重新刷新,但是此时还不能重新起库,需要重新从主库生成一个standby controlfile。
RMAN> BACKUP CURRENT CONTROLFILE FOR STANDBY FORMAT '/u01/app/oracle/oradata/tmp/ctl.bak';
oracle@standby's password:
ctl.bak 100% 9664KB 9.4MB/s 00:00
备库库起到nomount阶段:
SYS@dgtest_s>shutdown immediate
SYS@dgtest_s>startup nomount;
rman恢复控制文件
RMAN> RESTORE STANDBY CONTROLFILE FROM '/u01/app/oracle/oradata/tmp/ctl.bak';
SYS@dgtest_s> alter database mount;
SYS@dgtest_s>alter database recover managed standby database cancel;
SYS@dgtest_s>ALTER DATABASE CLEAR LOGFILE GROUP 1;
Database altered.
注:如果采用了standby log模式,不需要清空,如果清空会出现
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1;
ALTER DATABASE CLEAR LOGFILE GROUP 1
*
ERROR at line 1:
ORA-19527: physical standby redo log must be renamed
ORA-00312: online log 1 thread 1: '/u01/oradata/badly9/redo01.log'
说明:如果没有采用standby log模式,有几组需要清空几组
SYS@dgtest_s>ALTER DATABASE FLASHBACK OFF;
SYS@dgtest_s>ALTER DATABASE FLASHBACK ON;
SYS@dgtest_s>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
在主库中执行
SYS@dgtest>alter system switch logfile;
分别主备库中执行select max(sequence#) from v$archived_log;如果一致标示修复成功
SYS@dgtest>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
81
SYS@dgtest_s>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
81
至此GAP修复完毕。