sqlplus / as sysdba ALTER SYSTEM SETLOG_ARCHIVE_DEST_STATE_2=defer; ALTER SYSTEM SETLOG_ARCHIVE_DEST_STATE_2=enable;
AI写代码bash
* 1 * 2 * 3
查询是否存在GAP,确认主备是否同步:
1 2 3 4 5 6 7 8 9 10 11
sqlplus / as sysdba SELECT * FROM V$ARCHIVE_GAP; SELECT max(sequence#) from v$archived_log where applied='YES'; SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;
AI写代码bash
* 1 * 2 * 3 * 4
至此,DG GAP已被修复,以上方式为常规修复方式,各个版本都通用。
四、12C新特性修复
首先,模拟备库断电,主库切几个最新的归档,然后手工删掉,重新开启DG同步。
模拟GAP期间,有数据文件添加的情况:
1 2 3 4 5 6 7
##主库添加数据文件 altertablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;
AI写代码bash
* 1 * 2
📢 注意: 当前DG数据库已存在GAP,GAP日志为:30—31 。
a.记录备库当前SCN号
备库记录当前 scn 号:
1 2 3 4 5 6 7 8 9 10 11 12 13
sqlplus / as sysdba SELECT CURRENT_SCN FROM V$DATABASE; CURRENT_SCN ----------- 2600487
AI写代码bash
* 1 * 2 * 3 * 4 * 5
b.使用recover standby using service恢复
采用rman的新功能,recover standby using service,通过RMAN连接到target备库,然后用主库的service执行恢复备库命令。
语法:
RECOVER DATABASE FROM SERVICE < PRIMARY DB SERVICE NAME > NOREDO USING COMPRESSED BACKUPSET;
📢 注意: 确认主库的TNS已配置,这里的< PRIMARY DB SERVICE NAME >即 TNSNAME。
c.备库启动到nomount状态,恢复控制文件
备库启动到nomount状态:
1 2 3 4 5 6 7 8 9
sqlplus / as sysdba shutdown immediate startup nomount
AI写代码bash
* 1 * 2 * 3
备库通过from service恢复控制文件:
1 2 3 4 5 6 7
rman target / restore standby controlfile from service orcl;
AI写代码bash
* 1 * 2
备库开启到mount状态:
1 2 3 4 5 6 7
sqlplus / as sysdba alterdatabase mount;
AI写代码bash
* 1 * 2
d.备库恢复,修复GAP
检查主备GAP期间是否添加数据文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
sqlplus / as sysdba select file# from v$datafile where creation_change# > =2600487;
FILE# ---------- 13
AI写代码bash
* 1 * 2 * 3 * 4 * 5 * 6
restore 新添加的数据文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
rman target / run { SET NEWNAME FOR DATABASE TO'/oradata/ORCL_STBY/%f_%U'; RESTORE DATAFILE 13 FROM SERVICE orcl; }
AI写代码bash
* 1 * 2 * 3 * 4 * 5 * 6
由于主备的数据文件目录不一致,需要修改controlfile中数据文件位置:
1 2 3 4 5 6 7 8 9 10 11
rman target / catalog start with '/oradata/ORCL_STBY'; YES SWITCH DATABASE TO COPY;
AI写代码bash
* 1 * 2 * 3 * 4
将备库文件管理方式改为手动:
1 2 3 4 5 6 7
sqlplus / as sysdba alter system setstandby_file_management=MANUAL;
sqlplus / as sysdba alter system setstandby_file_management=AUTO;
AI写代码bash
* 1 * 2
恢复主备GAP:
1 2 3 4 5
recover database from service orcl noredo using compressed backupset;
AI写代码bash
* 1
📢 注意: 如果主备库文件目录不一致,则需要catalog切换控制文件中路径,否则报错:
e.开启备库日志应用,检查同步
检查主备scn是否一致
1 2 3 4 5 6 7 8 9 10 11
sqlplus / as sysdba col HXFNM for a100 set line222 select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;
AI写代码bash
* 1 * 2 * 3 * 4
主库切几次归档
1 2 3 4 5 6 7 8 9
sqlplus / as sysdba ALTERSYSTEM ARCHIVE LOGCURRENT; ALTERSYSTEM SWITCH LOGFILE;
AI写代码bash
* 1 * 2 * 3
开启备库应用日志
1 2 3 4 5 6 7 8 9 10 11
sqlplus / as sysdba alterdatabaseopen; alter pluggable databaseallopen; ALTERDATABASE RECOVER MANAGED STANDBY DATABASEUSINGCURRENT LOGFILE DISCONNECT FROMSESSION;
AI写代码bash
* 1 * 2 * 3 * 4
查看备库同步是否正常
1 2 3 4 5 6 7 8 9 10 11
sqlplus / as sysdba set line222 col member for a60 select t1.group#,t1.thread#,t1.bytes/1024/1024,t1.status,t2.member from gv$standby_log t1,gv$logfile t2 where t1.group#=t2.group#;
AI写代码bash
* 1 * 2 * 3 * 4
主库插入数据
1 2 3 4 5 6 7 8 9
sqlplus test/test@pdb01 insert into test values (999); commit;
AI写代码bash
* 1 * 2 * 3
备库查询是否实时同步
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
alter session set container=pdb01; select * from test.test; ID ---------- 1 2 999
channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:02 output file name=/oradata/ORCL_STBY/control01.ctl output file name=/oradata/ORCL_STBY/control02.ctl Finished restore at 19-APR-21
released channel: ORA_DISK_1 Statement processed Executing: alter system set standby_file_management=manual
contents of Memory Script: { setnewname for tempfile 1 to "/oradata/ORCL_STBY/temp01.dbf"; set newname for tempfile 2 to "/oradata/ORCL_STBY/pdbseed/temp012021-04-11_06-13-50-844-AM.dbf"; set newname for tempfile 3 to "/oradata/ORCL_STBY/BFA6BEE45A1E3605E053AC01A8C0DD20/datafile/o1_mf_temp_j749f5fy_.dbf"; switch tempfile all; set newname for datafile 1 to "/oradata/ORCL_STBY/system01.dbf"; set newname for datafile 3 to "/oradata/ORCL_STBY/sysaux01.dbf"; set newname for datafile 4 to "/oradata/ORCL_STBY/undotbs01.dbf"; set newname for datafile 5 to "/oradata/ORCL_STBY/pdbseed/system01.dbf"; set newname for datafile 6 to "/oradata/ORCL_STBY/pdbseed/sysaux01.dbf"; set newname for datafile 7 to "/oradata/ORCL_STBY/users01.dbf"; set newname for datafile 8 to "/oradata/ORCL_STBY/pdbseed/undotbs01.dbf"; set newname for datafile 9 to "/oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbf"; set newname for datafile 10 to "/oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbf"; set newname for datafile 11 to "/oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbf"; set newname for datafile 12 to "/oradata/ORCL_STBY/test01.dbf"; set newname for datafile 14 to "/oradata/ORCL/test02.dbf"; restore from service 'orcl' datafile 14; catalog datafilecopy "/oradata/ORCL_STBY/system01.dbf", "/oradata/ORCL_STBY/sysaux01.dbf", "/oradata/ORCL_STBY/undotbs01.dbf", "/oradata/ORCL_STBY/pdbseed/system01.dbf", "/oradata/ORCL_STBY/pdbseed/sysaux01.dbf", "/oradata/ORCL_STBY/users01.dbf", "/oradata/ORCL_STBY/pdbseed/undotbs01.dbf", "/oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbf", "/oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbf", "/oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbf", "/oradata/ORCL_STBY/test01.dbf", "/oradata/ORCL/test02.dbf"; switch datafile all; } executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /oradata/ORCL_STBY/temp01.dbf in control file renamed tempfile 2 to /oradata/ORCL_STBY/pdbseed/temp012021-04-11_06-13-50-844-AM.dbf in control file renamed tempfile 3 to /oradata/ORCL_STBY/BFA6BEE45A1E3605E053AC01A8C0DD20/datafile/o1_mf_temp_j749f5fy_.dbf in control file
channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00014 to /oradata/ORCL/test02.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:03 Finished restore at 19-APR-21
datafile 14 switched to datafile copy input datafile copy RECID=15 STAMP=1070263318file name=/oradata/ORCL/test02.dbf datafile 1 switched to datafile copy input datafile copy RECID=4 STAMP=1070263316 file name=/oradata/ORCL_STBY/system01.dbf datafile 3 switched to datafile copy input datafile copy RECID=5 STAMP=1070263317file name=/oradata/ORCL_STBY/sysaux01.dbf datafile 4 switched to datafile copy input datafile copy RECID=6 STAMP=1070263317 file name=/oradata/ORCL_STBY/undotbs01.dbf datafile 5 switched to datafile copy input datafile copy RECID=7 STAMP=1070263317file name=/oradata/ORCL_STBY/pdbseed/system01.dbf datafile 6 switched to datafile copy input datafile copy RECID=8 STAMP=1070263318file name=/oradata/ORCL_STBY/pdbseed/sysaux01.dbf datafile 7 switched to datafile copy input datafile copy RECID=9 STAMP=1070263318file name=/oradata/ORCL_STBY/users01.dbf datafile 8 switched to datafile copy input datafile copy RECID=10 STAMP=1070263318 file name=/oradata/ORCL_STBY/pdbseed/undotbs01.dbf datafile 9 switched to datafile copy input datafile copy RECID=11 STAMP=1070263318 file name=/oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbf datafile 10 switched to datafile copy input datafile copy RECID=12 STAMP=1070263318 file name=/oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbf datafile 11 switched to datafile copy input datafile copy RECID=13 STAMP=1070263318 file name=/oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbf datafile 12 switched to datafile copy input datafile copy RECID=14 STAMP=1070263318 file name=/oradata/ORCL_STBY/test01.dbf Executing: alter database rename file'/oradata/ORCL/redo01.log' to '/oradata/ORCL_STBY/redo01.log' Executing: alter database rename file'/oradata/ORCL/redo02.log' to '/oradata/ORCL_STBY/redo02.log' Executing: alter database rename file'/oradata/ORCL/redo03.log' to '/oradata/ORCL_STBY/redo03.log'
contents of Memory Script: { recover database from service 'orcl'; } executing Memory Script
Starting recover at 19-APR-21 using channel ORA_DISK_1 skipping datafile 5; already restored to SCN 2155383 skipping datafile 6; already restored to SCN 2155383 skipping datafile 8; already restored to SCN 2155383 skipping datafile 14; already restored to SCN 2658548 channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl destination for restore of datafile 00001: /oradata/ORCL_STBY/system01.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl destination for restore of datafile 00003: /oradata/ORCL_STBY/sysaux01.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl destination for restore of datafile 00004: /oradata/ORCL_STBY/undotbs01.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl destination for restore of datafile 00007: /oradata/ORCL_STBY/users01.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl destination for restore of datafile 00009: /oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl destination for restore of datafile 00010: /oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl destination for restore of datafile 00011: /oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:02 channel ORA_DISK_1: starting incremental datafile backup set restore channel ORA_DISK_1: using network backup set from service orcl destination for restore of datafile 00012: /oradata/ORCL_STBY/test01.dbf channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
starting media recovery
media recovery complete, elapsed time: 00:00:00 Finished recover at 19-APR-21 Executing: alter system set standby_file_management=auto Finished recover at 19-APR-21
sqlplus / as sysdba alter system setstandby_file_management=AUTO;
AI写代码bash
* 1 * 2
c.主库切日志,备库开启日志应用
检查主备scn是否一致:
1 2 3 4 5 6 7 8 9 10 11
sqlplus / as sysdba col HXFNM for a100 set line222 select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;
AI写代码bash
* 1 * 2 * 3 * 4
主库切几次归档:
1 2 3 4 5 6 7 8 9
sqlplus / as sysdba ALTERSYSTEM ARCHIVE LOGCURRENT; ALTERSYSTEM SWITCH LOGFILE;
AI写代码bash
* 1 * 2 * 3
开启备库应用日志:
1 2 3 4 5 6 7 8 9 10 11
sqlplus / as sysdba alterdatabaseopen; alter pluggable databaseallopen; ALTERDATABASE RECOVER MANAGED STANDBY DATABASEUSINGCURRENT LOGFILE DISCONNECT FROMSESSION;
AI写代码bash
* 1 * 2 * 3 * 4
查看备库同步是否正常:
1 2 3 4 5 6 7 8 9 10 11
sqlplus / as sysdba set line222 col member for a60 select t1.group#,t1.thread#,t1.bytes/1024/1024,t1.status,t2.member from gv$standby_log t1,gv$logfile t2 where t1.group#=t2.group#;
AI写代码bash
* 1 * 2 * 3 * 4
主库插入数据:
1 2 3 4 5 6 7 8 9
sqlplus test/test@pdb01 insert into test values (999); commit;
AI写代码bash
* 1 * 2 * 3
备库查询是否实时同步:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
sqlplus / as sysdba alter session set container=pdb01; select * from test.test; ID ---------- 1 2 999