一、介绍
DG GAP顾名思义就是:DG不同步,当备库不能接受到一个或多个主库的归档日志文件时候,就发生了GAP。
1、主库归档日志存在,可以通过配置Fetch Archive Log(FAL)参数,自动解决归档GAP。
2、主库归档日志丢失,需要人工干预来修复:
a.11G and before的常规处理步骤:
1.在主库上创建一个备库的控制文件 2.以备库的当前SCN号为起点,在主库上做一个增量备份 3.将增量备份拷贝到备库上 4.使用新的控制文件将备库启动到mount状态 5.将增量备份注册到RMAN的catalog,取消备库的恢复应用,恢复增量备份 6.开启备库的恢复进程
b.12C and later的新特性(RECOVER … FROM SERVICE)
c.18C and later的新特性(RECOVER STANDBY DATABASE FROM SERVICE)
Oracle随着版本的升级,逐渐将步骤缩减,进行封装,18C之后可谓是达到了所谓的一键刷新,恢复DG同步。
下面我们通过实验来进行展示:
首先,模拟备库断电,主库切几个最新的归档,然后手工删掉,重新开启DG同步。
##备库:ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;shutdown immediate##主库:alter system switch logfile;多次切归档##删除最近几个归档日志:rm 1_34_1070147137.arcrm 1_33_1070147137.arc##备库:startupALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;##查看GAPSQL> SELECT * FROM V$ARCHIVE_GAP;THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#---------- ------------- --------------1 32 34SQL> SELECT max(sequence#) from v$archived_log where applied='YES';MAX(SEQUENCE#)--------------31SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;PROCESS STATUS THREAD# SEQUENCE# BLOCK# BLOCKS--------- ------------ ---------- ---------- ---------- ----------ARCH CLOSING 1 38 1 40ARCH CLOSING 1 39 1 2ARCH CONNECTED 0 0 0 0ARCH CLOSING 1 37 1 2RFS IDLE 0 0 0 0RFS IDLE 0 0 0 0RFS IDLE 1 40 83 1MRP0 APPLYING_LOG 1 33 1 2457608 rows selected.-----------------------------------
二、11G and Before
1.在主库上创建一个备库的控制文件
SQL> alter database create standby controlfile as '/tmp/standby.ctl';Database altered.
2.以备库的当前SCN号为起点,在主库上做一个增量备份
--备库SQL> select to_char(current_scn) from v$database;TO_CHAR(CURRENT_SCN)----------------------------------------1086639--主库rman target /run{allocate channel c1 type disk;allocate channel c2 type disk;backup INCREMENTAL from scn 1086639 database format '/tmp/incre_%U';release channel c1;release channel c2;}-----------------------------------
3.将增量备份拷贝到备库上
--主库[oracle@orcl:/tmp]$ scp incre_0* oracle@orcl_stby:/home/oracleoracle@orcl_stby's password:incre_0cvsjs8b_1_1 100% 144KB 144.0KB/s 00:00incre_0dvsjs9a_1_1 100% 416KB 416.0KB/s 00:00incre_0evsjs9a_1_1 100% 144KB 144.0KB/s 00:00incre_0fvsjs9b_1_1 100% 9856KB 9.6MB/s 00:00[oracle@orcl:/tmp]$ scp standby.ctl oracle@orcl_stby:/home/oracleoracle@orcl_stby's password:standby.ctl-----------------------------------
4.使用新的控制文件将备库启动到mount状态
shutdown immediatestartup nomountrman target /RMAN> restore controlfile from '/home/oracle/standby.ctl';Starting restore at 18-APR-21using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=19 device type=DISKchannel ORA_DISK_1: copied control file copyoutput file name=/oradata/orcl/control01.ctloutput file name=/u01/app/oracle/fast_recovery_area/orcl/control02.ctlFinished restore at 18-APR-21alter database mount;
5.增量备份注册到RMAN的catalog,取消日志应用,恢复增量备份
--备库ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;rman target /RMAN> catalog start with '/home/oracle/';YESRMAN> recover database noredo;Starting recover at 18-APR-21allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=29 device type=DISKchannel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setdestination for restore of datafile 00001: /oradata/orcl/system01.dbfdestination for restore of datafile 00004: /oradata/orcl/users01.dbfdestination for restore of datafile 00006: /oradata/orcl/test01.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/incre_0evsjs9a_1_1channel ORA_DISK_1: piece handle=/home/oracle/incre_0evsjs9a_1_1 tag=TAG20210418T133122channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setdestination for restore of datafile 00002: /oradata/orcl/sysaux01.dbfdestination for restore of datafile 00003: /oradata/orcl/undotbs01.dbfdestination for restore of datafile 00005: /oradata/orcl/example01.dbfchannel ORA_DISK_1: reading from backup piece /home/oracle/incre_0dvsjs9a_1_1channel ORA_DISK_1: piece handle=/home/oracle/incre_0dvsjs9a_1_1 tag=TAG20210418T133122channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:00:01Finished recover at 18-APR-21-----------------------------------
6.开启备库的恢复进程
alter database open read only;ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;--GAP已修复SQL> SELECT * FROM V$ARCHIVE_GAP;no rows selectedSQL> SELECT max(sequence#) from v$archived_log where applied='YES';MAX(SEQUENCE#)--------------41SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;PROCESS STATUS THREAD# SEQUENCE# BLOCK# BLOCKS--------- ------------ ---------- ---------- ---------- ----------ARCH CONNECTED 0 0 0 0ARCH CONNECTED 0 0 0 0ARCH CONNECTED 0 0 0 0ARCH CLOSING 1 41 1 257RFS IDLE 0 0 0 0RFS IDLE 0 0 0 0RFS IDLE 1 42 19969 1MRP0 APPLYING_LOG 1 42 19969 2457608 rows selected.-----------------------------------
三、12C and Later
SQL> SELECT * FROM V$ARCHIVE_GAP;THREAD# LOW_SEQUENCE# HIGH_SEQUENCE# CON_ID---------- ------------- -------------- ----------1 30 31 1SQL> SELECT max(sequence#) from v$archived_log where applied='YES';MAX(SEQUENCE#)--------------29SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;PROCESS STATUS THREAD# SEQUENCE# BLOCK# BLOCKS--------- ------------ ---------- ---------- ---------- ----------ARCH CONNECTED 0 0 0 0DGRD ALLOCATED 0 0 0 0DGRD ALLOCATED 0 0 0 0ARCH CONNECTED 0 0 0 0ARCH CLOSING 1 29 1 268ARCH CONNECTED 0 0 0 0RFS IDLE 1 34 184 1RFS IDLE 1 0 0 0RFS IDLE 0 0 0 0RFS IDLE 0 0 0 0RFS IDLE 0 0 0 0MRP0 WAIT_FOR_GAP 1 30 0 0DGRD ALLOCATED 0 0 0 013 rows selected.[oracle@orcl_stby:/archivelog]$ lltotal 11508-rw-r-----. 1 oracle oinstall 11634176 Apr 19 02:05 1_28_1069567741.arc-rw-r-----. 1 oracle oinstall 137728 Apr 19 02:08 1_29_1069567741.arc-rw-r-----. 1 oracle oinstall 1536 Apr 19 02:08 1_32_1069567741.arc-rw-r-----. 1 oracle oinstall 3584 Apr 19 02:08 1_33_1069567741.arc
1.记录主库和备库当前SCN号
--主库SQL> set line222SQL> col HXFNM for a100SQL> select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;FILE_NUM HXFNM FHSCN---------- ---------------------------------------------------------------------------------------------------- --------------------1 /oradata/ORCL/system01.dbf 26005223 /oradata/ORCL/sysaux01.dbf 26005224 /oradata/ORCL/undotbs01.dbf 26005225 /oradata/ORCL/pdbseed/system01.dbf 21553836 /oradata/ORCL/pdbseed/sysaux01.dbf 21553837 /oradata/ORCL/users01.dbf 26005228 /oradata/ORCL/pdbseed/undotbs01.dbf 21553839 /oradata/ORCL/BFA6BEE45A1E3605E053AC01A8 260052210 /oradata/ORCL/BFA6BEE45A1E3605E053AC01A8 260052211 /oradata/ORCL/BFA6BEE45A1E3605E053AC01A8 260052212 /oradata/ORCL/test01.dbf 2600522--备库SQL> set line222SQL> col HXFNM for a100SQL> select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;FILE_NUM HXFNM FHSCN---------- ---------------------------------------------------------------------------------------------------- --------------------1 /oradata/ORCL_STBY/system01.dbf 26004883 /oradata/ORCL_STBY/sysaux01.dbf 26004884 /oradata/ORCL_STBY/undotbs01.dbf 26004885 /oradata/ORCL_STBY/pdbseed/system01.dbf 21553836 /oradata/ORCL_STBY/pdbseed/sysaux01.dbf 21553837 /oradata/ORCL_STBY/users01.dbf 26004888 /oradata/ORCL_STBY/pdbseed/undotbs01.dbf 21553839 /oradata/ORCL_STBY/PDB01/o1_mf_system_j7 260048810 /oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j7 260048811 /oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_ 260048812 /oradata/ORCL_STBY/test01.dbf 2600488SQL> SELECT CURRENT_SCN FROM V$DATABASE;CURRENT_SCN-----------2600487
2.使用recover standby using service恢复
采用rman的新功能,recover standby using service,通过RMAN连接到target备库,然后用主库的service执行恢复备库命令。
语法:
RECOVER DATABASE FROM SERVICE < PRIMARY DB SERVICE NAME > NOREDO USING COMPRESSED BACKUPSET;
模拟GAP期间,有数据文件添加的情况:
-主库添加数据文件SQL> alter tablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;Tablespace altered.--检查备库scn是否添加数据文件SQL> select file# from v$datafile where creation_change# > =2600487;FILE#----------13--备库启动到nomount状态shutdown immediatestartup nomount--rman恢复rman target /##恢复控制文件RMAN> restore standby controlfile from service orcl;Starting restore at 19-APR-21using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=739 device type=DISKchannel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: using network backup set from service orclchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/oradata/ORCL_STBY/control01.ctloutput file name=/oradata/ORCL_STBY/control02.ctlFinished restore at 19-APR-21##mount数据库alter database mount;##restore新添加的数据文件run{SET NEWNAME FOR DATABASE TO '/oradata/ORCL_STBY/%f_%U';RESTORE DATAFILE 13 FROM SERVICE orcl;}executing command: SET NEWNAMEStarting restore at 19-APR-21allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=503 device type=DISKchannel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: using network backup set from service orclchannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00013 to /oradata/ORCL_STBY/13_data_D-ORCL_TS-TEST_FNO-13channel ORA_DISK_1: restore complete, elapsed time: 00:00:03Finished restore at 19-APR-21##由于主备的数据文件目录不一致,需要修改controlfile中数据文件位置catalog start with '/oradata/ORCL_STBY';YESSWITCH DATABASE TO COPY;##rename tempfile && logfilealter system set standby_file_management=MANUAL;##logfilealter 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';##tempfilealter 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';alter system set standby_file_management=AUTO;##恢复数据库RMAN> recover database from service orcl noredo using compressed backupset;Starting recover at 19-APR-21allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=2 device type=DISKskipping datafile 5; already restored to SCN 2155383skipping datafile 6; already restored to SCN 2155383skipping datafile 8; already restored to SCN 2155383channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orcldestination for restore of datafile 00001: /oradata/ORCL_STBY/system01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orcldestination for restore of datafile 00003: /oradata/ORCL_STBY/sysaux01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orcldestination for restore of datafile 00004: /oradata/ORCL_STBY/undotbs01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:02channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orcldestination for restore of datafile 00007: /oradata/ORCL_STBY/users01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orcldestination for restore of datafile 00009: /oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orcldestination for restore of datafile 00010: /oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orcldestination for restore of datafile 00011: /oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orcldestination for restore of datafile 00012: /oradata/ORCL_STBY/test01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01Finished recover at 19-APR-21
Notes:如果主备库文件目录不一致,则需要catalog切换控制文件中路径,否则报错:
RMAN> recover database from service orcl noredo using compressed backupset;Starting recover at 19-APR-21using channel ORA_DISK_1channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using compressed network backup set from service orclRMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of recover command at 04/19/2021 02:25:29ORA-19625: error identifying file /oradata/ORCL/system01.dbfORA-27037: unable to obtain file statusLinux-x86_64 Error: 2: No such file or directoryAdditional information: 7-----------------------------------
3.开启备库日志应用
--此时主备库的sch已恢复一致SQL> col HXFNM for a100SQL> set line222SQL> select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;FILE_NUM HXFNM FHSCN---------- ---------------------------------------------------------------------------------------------------- --------------------1 /oradata/ORCL_STBY/system01.dbf 26035123 /oradata/ORCL_STBY/sysaux01.dbf 26035144 /oradata/ORCL_STBY/undotbs01.dbf 26035165 /oradata/ORCL_STBY/pdbseed/system01.dbf 21553836 /oradata/ORCL_STBY/pdbseed/sysaux01.dbf 21553837 /oradata/ORCL_STBY/users01.dbf 26035188 /oradata/ORCL_STBY/pdbseed/undotbs01.dbf 21553839 /oradata/ORCL_STBY/PDB01/o1_mf_system_j7 260352110 /oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j7 260352411 /oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_ 260352712 /oradata/ORCL_STBY/test01.dbf 260353011 rows selected.--主库需要切几次归档ALTER SYSTEM ARCHIVE LOG CURRENT;或者ALTER SYSTEM SWITCH LOGFILE;--开启备库应用日志alter database open;alter pluggable database all open;ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
4、测试同步情况
--查看standby日志是否正常set line222col member for a60select 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#;GROUP# THREAD# T1.BYTES/1024/1024 STATUS MEMBER---------- ---------- ------------------ ---------- ------------------------------------------------------------4 1 120 ACTIVE /oradata/ORCL/standby_redo04.log5 1 120 UNASSIGNED /oradata/ORCL/standby_redo05.log6 1 120 UNASSIGNED /oradata/ORCL/standby_redo06.log7 1 120 UNASSIGNED /oradata/ORCL/standby_redo07.log--主库插入数据sqlplus test/test@pdb01insert into test values (999);commit;--备库查询SQL> alter session set container=pdb01;SQL> select * from test.test;ID----------12999--备库已同步
三、18C and Later
将RECOVER STANDBY DATABASE命令与FROM SERVICE子句一起使用,以通过对主数据库进行的更改来刷新物理备用数据库。
备库可以直接在开启状态进行刷新。
语法:
RECOVER STANDBY DATABASE FROM SERVICE primary_db;
模拟GAP期间,有数据文件添加的情况:
--备库存在GAPSQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;PROCESS STATUS THREAD# SEQUENCE# BLOCK# BLOCKS--------- ------------ ---------- ---------- ---------- ----------ARCH CONNECTED 0 0 0 0DGRD ALLOCATED 0 0 0 0DGRD ALLOCATED 0 0 0 0ARCH CONNECTED 0 0 0 0ARCH CONNECTED 0 0 0 0ARCH CONNECTED 0 0 0 0RFS IDLE 1 0 0 0RFS IDLE 1 72 119 1RFS IDLE 0 0 0 0RFS IDLE 0 0 0 0MRP0 WAIT_FOR_GAP 1 70 0 011 rows selected.SQL> SELECT max(sequence#) from v$archived_log where applied='YES';MAX(SEQUENCE#)--------------69SQL> select * from v$archive_gap;THREAD# LOW_SEQUENCE# HIGH_SEQUENCE# CON_ID---------- ------------- -------------- ----------1 70 70 1--主库添加数据文件SQL> alter tablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;Tablespace altered.
1、执行RECOVER STANDBY DATABASE FROM SERVICE刷新备库:
通过执行过程可以发现:
RECOVER STANDBY DATABASE命令重新启动备用实例,从主数据库刷新控制文件,并自动重命名数据文件,临时文件和联机日志。 它可以还原添加到主数据库中的新数据文件,并还原到当前时间的备用数据库。
##备库##取消日志应用ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;##开始刷新备库rman target /RMAN> RECOVER STANDBY DATABASE FROM SERVICE orcl;Starting recover at 19-APR-21using target database control file instead of recovery catalogOracle instance startedTotal System Global Area 3355441944 bytesFixed Size 9141016 bytesVariable Size 671088640 bytesDatabase Buffers 2667577344 bytesRedo Buffers 7634944 bytescontents of Memory Script:{restore standby controlfile from service 'orcl';alter database mount standby database;}executing Memory ScriptStarting restore at 19-APR-21allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=502 device type=DISKchannel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: using network backup set from service orclchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:02output file name=/oradata/ORCL_STBY/control01.ctloutput file name=/oradata/ORCL_STBY/control02.ctlFinished restore at 19-APR-21released channel: ORA_DISK_1Statement processedExecuting: alter system set standby_file_management=manualcontents 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' datafile14;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 Scriptexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMErenamed tempfile 1 to /oradata/ORCL_STBY/temp01.dbf in control filerenamed tempfile 2 to /oradata/ORCL_STBY/pdbseed/temp012021-04-11_06-13-50-844-AM.dbf in control filerenamed tempfile 3 to /oradata/ORCL_STBY/BFA6BEE45A1E3605E053AC01A8C0DD20/datafile/o1_mf_temp_j749f5fy_.dbf in control fileexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting restore at 19-APR-21allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=504 device type=DISKchannel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: using network backup set from service orclchannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00014 to /oradata/ORCL/test02.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:03Finished restore at 19-APR-21cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/system01.dbf RECID=4 STAMP=1070263316cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/sysaux01.dbf RECID=5 STAMP=1070263317cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/undotbs01.dbf RECID=6 STAMP=1070263317cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/pdbseed/system01.dbf RECID=7 STAMP=1070263317cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/pdbseed/sysaux01.dbf RECID=8 STAMP=1070263318cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/users01.dbf RECID=9 STAMP=1070263318cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/pdbseed/undotbs01.dbf RECID=10 STAMP=1070263318cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbf RECID=11 STAMP=1070263318cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbf RECID=12 STAMP=1070263318cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbf RECID=13 STAMP=1070263318cataloged datafile copydatafile copy file name=/oradata/ORCL_STBY/test01.dbf RECID=14 STAMP=1070263318cataloged datafile copydatafile copy file name=/oradata/ORCL/test02.dbf RECID=15 STAMP=1070263318datafile 14 switched to datafile copyinput datafile copy RECID=15 STAMP=1070263318 file name=/oradata/ORCL/test02.dbfdatafile 1 switched to datafile copyinput datafile copy RECID=4 STAMP=1070263316 file name=/oradata/ORCL_STBY/system01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=5 STAMP=1070263317 file name=/oradata/ORCL_STBY/sysaux01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=6 STAMP=1070263317 file name=/oradata/ORCL_STBY/undotbs01.dbfdatafile 5 switched to datafile copyinput datafile copy RECID=7 STAMP=1070263317 file name=/oradata/ORCL_STBY/pdbseed/system01.dbfdatafile 6 switched to datafile copyinput datafile copy RECID=8 STAMP=1070263318 file name=/oradata/ORCL_STBY/pdbseed/sysaux01.dbfdatafile 7 switched to datafile copyinput datafile copy RECID=9 STAMP=1070263318 file name=/oradata/ORCL_STBY/users01.dbfdatafile 8 switched to datafile copyinput datafile copy RECID=10 STAMP=1070263318 file name=/oradata/ORCL_STBY/pdbseed/undotbs01.dbfdatafile 9 switched to datafile copyinput datafile copy RECID=11 STAMP=1070263318 file name=/oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbfdatafile 10 switched to datafile copyinput datafile copy RECID=12 STAMP=1070263318 file name=/oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbfdatafile 11 switched to datafile copyinput datafile copy RECID=13 STAMP=1070263318 file name=/oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbfdatafile 12 switched to datafile copyinput datafile copy RECID=14 STAMP=1070263318 file name=/oradata/ORCL_STBY/test01.dbfExecuting: 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 ScriptStarting recover at 19-APR-21using channel ORA_DISK_1skipping datafile 5; already restored to SCN 2155383skipping datafile 6; already restored to SCN 2155383skipping datafile 8; already restored to SCN 2155383skipping datafile 14; already restored to SCN 2658548channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using network backup set from service orcldestination for restore of datafile 00001: /oradata/ORCL_STBY/system01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using network backup set from service orcldestination for restore of datafile 00003: /oradata/ORCL_STBY/sysaux01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using network backup set from service orcldestination for restore of datafile 00004: /oradata/ORCL_STBY/undotbs01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using network backup set from service orcldestination for restore of datafile 00007: /oradata/ORCL_STBY/users01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using network backup set from service orcldestination for restore of datafile 00009: /oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using network backup set from service orcldestination for restore of datafile 00010: /oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using network backup set from service orcldestination for restore of datafile 00011: /oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:02channel ORA_DISK_1: starting incremental datafile backup set restorechannel ORA_DISK_1: using network backup set from service orcldestination for restore of datafile 00012: /oradata/ORCL_STBY/test01.dbfchannel ORA_DISK_1: restore complete, elapsed time: 00:00:01starting media recoverymedia recovery complete, elapsed time: 00:00:00Finished recover at 19-APR-21Executing: alter system set standby_file_management=autoFinished recover at 19-APR-21-----------------------------------
2、rename standby log
—刷新过后,redo log路径已修改,standby log路径未修改。
--刷新过后,redo log路径已修改,standby log路径未修改。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--rename tempfile && logfilealter system set standby_file_management=MANUAL;--clear logalter database clear logfile group 4;alter database clear logfile group 5;alter database clear logfile group 6;alter database clear logfile group 7;--standby logalter 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';-----------------------------------
3、主库切日志,备库开启日志应用
--主库需要切几次归档ALTER SYSTEM ARCHIVE LOG CURRENT;或者ALTER SYSTEM SWITCH LOGFILE;--开启备库应用日志alter database open;alter pluggable database all open;ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;-----------------------------------
4、测试同步情况
--查看standby日志是否正常set line222col member for a60select 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#;GROUP# THREAD# T1.BYTES/1024/1024 STATUS MEMBER---------- ---------- ------------------ ---------- ------------------------------------------------------------4 1 120 ACTIVE /oradata/ORCL/standby_redo04.log5 1 120 UNASSIGNED /oradata/ORCL/standby_redo05.log6 1 120 UNASSIGNED /oradata/ORCL/standby_redo06.log7 1 120 UNASSIGNED /oradata/ORCL/standby_redo07.log--主库插入数据sqlplus test/test@pdb01insert into test values (999);commit;--备库查询SQL> alter session set container=pdb01;Session altered.SQL> select * from test.test;ID----------1299999923377886 rows selected.--备库已同步
