sqlplus / as sysdba ##logfile alter database clear logfile group 1; alter database clear logfile group 2; alter database clear logfile group 3; alter database clear logfile group 4; alter database clear logfile group 5; alter database clear logfile group 6; alter database clear logfile group 7; alter database rename file '/oradata/ORCL/redo03.log' to '/oradata/ORCL_STBY/redo03.log'; alter database rename file '/oradata/ORCL/redo02.log' to '/oradata/ORCL_STBY/redo02.log'; alter database rename file '/oradata/ORCL/redo01.log' to '/oradata/ORCL_STBY/redo01.log'; alter database rename file '/oradata/ORCL/standby_redo04.log' to '/oradata/ORCL_STBY/standby_redo04.log'; alter database rename file '/oradata/ORCL/standby_redo05.log' to '/oradata/ORCL_STBY/standby_redo05.log'; alter database rename file '/oradata/ORCL/standby_redo06.log' to '/oradata/ORCL_STBY/standby_redo06.log'; alter database rename file '/oradata/ORCL/standby_redo07.log' to '/oradata/ORCL_STBY/standby_redo07.log'; ##tempfile alter database rename file '/oradata/ORCL/temp01.dbf' to '/oradata/ORCL_STBY/temp01.dbf'; alter database rename file '/oradata/ORCL/pdbseed/temp012021-04-11_06-13-50-844-AM.dbf' to '/oradata/ORCL_STBY/pdbseed/temp012021-04-11_06-13-50-844-AM.dbf'; alter database rename file '/oradata/ORCL/BFA6BEE45A1E3605E053AC01A8C0DD20/datafile/o1_mf_temp_j749f5fy_.dbf' to '/oradata/ORCL_STBY/BFA6BEE45A1E3605E053AC01A8C0DD20/datafile/o1_mf_temp_j749f5fy_.dbf';
备库重命名完后再改为自动:
1 2
sqlplus / as sysdba alter system set standby_file_management=AUTO;
恢复主备GAP:
1
recover database from service orcl noredo using compressed backupset;
📢 注意: 如果主备库文件目录不一致,则需要catalog切换控制文件中路径,否则报错:
e.开启备库日志应用,检查同步
检查主备scn是否一致
1 2 3 4
sqlplus / as sysdba col HXFNM for a100 set line222 select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;
主库切几次归档
1 2 3
sqlplus / as sysdba ALTER SYSTEM ARCHIVE LOG CURRENT; ALTER SYSTEM SWITCH LOGFILE;
开启备库应用日志
1 2 3 4
sqlplus / as sysdba alter database open; alter pluggable database all open; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
查看备库同步是否正常
1 2 3 4
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#;
主库插入数据
1 2 3
sqlplus test/test@pdb01 insert into test values (999); commit;
备库查询是否实时同步
1 2 3 4 5 6 7
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: { set newname 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=1070263318 file 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=1070263317 file 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=1070263317 file name=/oradata/ORCL_STBY/pdbseed/system01.dbf datafile 6 switched to datafile copy input datafile copy RECID=8 STAMP=1070263318 file name=/oradata/ORCL_STBY/pdbseed/sysaux01.dbf datafile 7 switched to datafile copy input datafile copy RECID=9 STAMP=1070263318 file 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
方便大家查看,于是记录恢复全过程,通过以上执行过程,可以看到:
RECOVER STANDBY DATABASE命令重新启动备用实例。
从主数据库刷新控制文件,并自动重命名数据文件,临时文件和联机日志。
它可以还原添加到主数据库中的新数据文件,并还原到当前时间的备用数据库。
b.备库修改standby log路径
发现刷新过后,备库redo log路径已修改,standby log路径未修改,因此手动修改。
查询备库的日志文件路径:
1 2 3 4 5 6 7 8 9 10 11 12
sqlplus / as sysdba SQL> select member from v$logfile;
MEMBER -------------------------------------------------------------------------------- /oradata/ORCL_STBY/redo03.log /oradata/ORCL_STBY/redo02.log /oradata/ORCL_STBY/redo01.log /oradata/ORCL/standby_redo04.log /oradata/ORCL/standby_redo05.log /oradata/ORCL/standby_redo06.log /oradata/ORCL/standby_redo07.log
关闭备库文件自动管理:
1 2
sqlplus / as sysdba alter system set standby_file_management=MANUAL;
清理standby log:
1 2 3 4 5
sqlplus / as sysdba alter database clear logfile group 4; alter database clear logfile group 5; alter database clear logfile group 6; alter database clear logfile group 7;
修改standby log路径:
1 2 3 4 5
sqlplus / as sysdba alter database rename file '/oradata/ORCL/standby_redo04.log' to '/oradata/ORCL_STBY/standby_redo04.log'; alter database rename file '/oradata/ORCL/standby_redo05.log' to '/oradata/ORCL_STBY/standby_redo05.log'; alter database rename file '/oradata/ORCL/standby_redo06.log' to '/oradata/ORCL_STBY/standby_redo06.log'; alter database rename file '/oradata/ORCL/standby_redo07.log' to '/oradata/ORCL_STBY/standby_redo07.log';
修改完后打开备库文件自动管理:
1 2
sqlplus / as sysdba alter system set standby_file_management=AUTO;
c.主库切日志,备库开启日志应用
检查主备scn是否一致:
1 2 3 4
sqlplus / as sysdba col HXFNM for a100 set line222 select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;
主库切几次归档:
1 2 3
sqlplus / as sysdba ALTER SYSTEM ARCHIVE LOG CURRENT; ALTER SYSTEM SWITCH LOGFILE;
开启备库应用日志:
1 2 3 4
sqlplus / as sysdba alter database open; alter pluggable database all open; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
查看备库同步是否正常:
1 2 3 4
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#;
主库插入数据:
1 2 3
sqlplus test/test@pdb01 insert into test values (999); commit;
备库查询是否实时同步:
1 2 3 4 5 6 7 8
sqlplus / as sysdba alter session set container=pdb01; select * from test.test; ID ---------- 1 2 999