DG GAP 顧名思義就是:DG不同步,當備庫不能接受到一個或多個主庫的歸檔日志文件時候,就發(fā)生了 GAP。
那么,如果遇到GAP如何修復呢?且聽我細細道來~
DG GAP 主要分為以下兩類情況:
1、主庫歸檔日志存在,可以通過配置 Fetch Archive Log(FAL) 參數(shù),自動解決歸檔 GAP。
2、主庫歸檔日志丟失,需要人工干預
來修復。
不同 Oracle 版本的 GAP 修復方式也不盡相同,下面分別介紹不同版本的方式!
11G 的處理步驟:
a.在主庫上創(chuàng)建一個備庫的控制文件
b.以備庫的當前SCN號為起點,在主庫上做一個增量備份
c.將增量備份拷貝到備庫上
d.使用新的控制文件將備庫啟動到mount狀態(tài)
e.將增量備份注冊到RMAN的catalog,取消備庫的恢復應用,恢復增量備份
f.開啟備庫的恢復進程
12C 的新特性(RECOVER … FROM SERVICE)
18C 的新特性(RECOVER STANDBY DATABASE FROM SERVICE)
Oracle隨著版本的升級,逐漸將步驟縮減,進行封裝,18C之后可謂是達到了所謂的一鍵刷新,恢復DG同步。
下面我們通過實驗來進行演示如何修復:
安裝測試環(huán)境可以使用博主編寫的 Oracle 一鍵安裝腳本,同時支持單機和 RAC 集群模式!
開源項目:Install Oracle Database By Scripts!
更多更詳細的腳本使用方式可以訂閱專欄:Oracle一鍵安裝腳本。
首先,模擬備庫斷電,主庫切幾個最新的歸檔,然后手工刪掉,重新開啟DG同步。
備庫停止DG同步進程:
sqlplus / as sysdba
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
shutdown immediate
主庫切換多次歸檔:
sqlplus / as sysdba
alter system switch logfile;
主庫刪除最近幾個歸檔日志:
rm 1_34_1070147137.arc
rm 1_33_1070147137.arc
備庫開啟同步進程:
startup
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
查看GAP:
sqlplus / as sysdba
SELECT * FROM V$ARCHIVE_GAP;
THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
---------- ------------- --------------
1 32 34
SELECT max(sequence#) from v$archived_log where applied='YES';
MAX(SEQUENCE#)
--------------
31
📢 注意: 當前DG數(shù)據(jù)庫已存在GAP,GAP日志為:32—34。
alter database create standby controlfile as '/tmp/standby.ctl';
備庫查詢當前 scn 號:
sqlplus / as sysdba
select to_char(current_scn) from v$database;
TO_CHAR(CURRENT_SCN)
----------------------------------------
1086639
確認主備GAP期間是否新增數(shù)據(jù)文件:
sqlplus / as sysdba
select file# from v$datafile where creation_change# > =1086639;
主庫根據(jù)備庫scn號進行增量備份:
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;
}
📢 注意: 如果存在新增數(shù)據(jù)文件,備庫恢復時需要先restore新添加的數(shù)據(jù)文件。
主庫拷貝增量備份和控制文件你至備庫:
scp incre_0* oracle@orcl_stby:/home/oracle
scp standby.ctl oracle@orcl_stby:/home/oracle
📢 注意: 確認備庫的磁盤空間是否足夠存放。
備庫關閉數(shù)據(jù)庫實例,開啟至nomount狀態(tài):
sqlplus / as sysdba
shutdown immediate
startup nomount
備庫恢復新的控制文件:
rman target /
restore controlfile from '/home/oracle/standby.ctl';
備庫開啟到mount狀態(tài):
alter database mount;
確認備庫已關閉DG同步進程:
sqlplus / as sysdba
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
備庫rman注冊增量備份文件:
rman target /
catalog start with '/home/oracle/';
YES
備庫開啟恢復增量備份:
recover database noredo;
備庫開啟日志同步進程:
sqlplus / as sysdba
alter database open read only;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
主庫重新激活同步:
sqlplus / as sysdba
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=defer;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=enable;
查詢是否存在GAP,確認主備是否同步:
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;
至此,DG GAP已被修復,以上方式為常規(guī)修復方式,各個版本都通用。
首先,模擬備庫斷電,主庫切幾個最新的歸檔,然后手工刪掉,重新開啟DG同步。
模擬GAP期間,有數(shù)據(jù)文件添加的情況:
##主庫添加數(shù)據(jù)文件
alter tablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;
📢 注意: 當前DG數(shù)據(jù)庫已存在GAP,GAP日志為:30—31 。
備庫記錄當前 scn 號:
sqlplus / as sysdba
SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
2600487
采用rman的新功能,recover standby using service
,通過RMAN連接到target備庫,然后用主庫的service執(zhí)行恢復備庫命令。
語法:
RECOVER DATABASE FROM SERVICE < PRIMARY DB SERVICE NAME > NOREDO USING COMPRESSED BACKUPSET;
📢 注意: 確認主庫的TNS已配置,這里的< PRIMARY DB SERVICE NAME >即 TNSNAME。
備庫啟動到nomount狀態(tài):
sqlplus / as sysdba
shutdown immediate
startup nomount
備庫通過from service恢復控制文件:
rman target /
restore standby controlfile from service orcl;
備庫開啟到mount狀態(tài):
sqlplus / as sysdba
alter database mount;
檢查主備GAP期間是否添加數(shù)據(jù)文件:
sqlplus / as sysdba
select file# from v$datafile where creation_change# > =2600487;
FILE#
----------
13
restore 新添加的數(shù)據(jù)文件:
rman target /
run
{
SET NEWNAME FOR DATABASE TO '/oradata/ORCL_STBY/%f_%U';
RESTORE DATAFILE 13 FROM SERVICE orcl;
}
由于主備的數(shù)據(jù)文件目錄不一致,需要修改controlfile中數(shù)據(jù)文件位置:
rman target /
catalog start with '/oradata/ORCL_STBY';
YES
SWITCH DATABASE TO COPY;
將備庫文件管理方式改為手動:
sqlplus / as sysdba
alter system set standby_file_management=MANUAL;
重命名 tempfile && logfile:
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';
備庫重命名完后再改為自動:
sqlplus / as sysdba
alter system set standby_file_management=AUTO;
恢復主備GAP:
recover database from service orcl noredo using compressed backupset;
📢 注意: 如果主備庫文件目錄不一致,則需要catalog切換控制文件中路徑,否則報錯:
sqlplus / as sysdba
col HXFNM for a100
set line222
select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;
sqlplus / as sysdba
ALTER SYSTEM ARCHIVE LOG CURRENT;
ALTER SYSTEM SWITCH LOGFILE;
sqlplus / as sysdba
alter database open;
alter pluggable database all open;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
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#;
sqlplus test/test@pdb01
insert into test values (999);
commit;
alter session set container=pdb01;
select * from test.test;
ID
----------
1
2
999
至此,GAP已修復完成,可以發(fā)現(xiàn),12C這個新特性,將一些步驟進行了省略和封裝,進一步減少了我們的操作步驟,但是內部的原理仍然是一致的。
18C 新特性是在 12C 的基礎上,將 RECOVER STANDBY DATABASE 命令與 FROM SERVICE 子句一起使用,以通過對主數(shù)據(jù)庫進行的更改來刷新物理備用數(shù)據(jù)庫。備庫可以直接在開啟狀態(tài)進行刷新。
語法:
RECOVER STANDBY DATABASE FROM SERVICE primary_db;
首先,模擬備庫斷電,主庫切幾個最新的歸檔,然后手工刪掉,重新開啟DG同步。
模擬GAP期間,有數(shù)據(jù)文件添加的情況:
##主庫添加數(shù)據(jù)文件
alter tablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;
📢 注意: 當前 DG 數(shù)據(jù)庫已存在 GAP,GAP 日志為:69—70。
下面演示一下,如何使用一行命令在線修復DG GAP:
備庫取消日志應用:
sqlplus / as sysdba
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
備庫執(zhí)行修復命令,開始在線刷新備庫:
rman target /
RMAN> RECOVER STANDBY DATABASE FROM SERVICE orcl;
Starting recover at 19-APR-21
using target database control file instead of recovery catalog
Oracle instance started
Total System Global Area3355441944 bytes
Fixed Size 9141016 bytes
Variable Size671088640 bytes
Database Buffers2667577344 bytes
Redo Buffers 7634944 bytes
contents of Memory Script:
{
restore standby controlfile from service 'orcl';
alter database mount standby database;
}
executing Memory Script
Starting restore at 19-APR-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=502 device type=DISK
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
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 19-APR-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=504 device type=DISK
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
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/system01.dbf RECID=4 STAMP=1070263316
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/sysaux01.dbf RECID=5 STAMP=1070263317
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/undotbs01.dbf RECID=6 STAMP=1070263317
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/pdbseed/system01.dbf RECID=7 STAMP=1070263317
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/pdbseed/sysaux01.dbf RECID=8 STAMP=1070263318
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/users01.dbf RECID=9 STAMP=1070263318
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/pdbseed/undotbs01.dbf RECID=10 STAMP=1070263318
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/PDB01/o1_mf_system_j749f5d5_.dbf RECID=11 STAMP=1070263318
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/PDB01/o1_mf_sysaux_j749f5fw_.dbf RECID=12 STAMP=1070263318
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/PDB01/o1_mf_undotbs1_j749f5fx_.dbf RECID=13 STAMP=1070263318
cataloged datafile copy
datafile copy file name=/oradata/ORCL_STBY/test01.dbf RECID=14 STAMP=1070263318
cataloged datafile copy
datafile copy file name=/oradata/ORCL/test02.dbf RECID=15 STAMP=1070263318
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
方便大家查看,于是記錄恢復全過程,通過以上執(zhí)行過程,可以看到:
發(fā)現(xiàn)刷新過后,備庫redo log路徑已修改,standby log路徑未修改,因此手動修改。
查詢備庫的日志文件路徑:
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
關閉備庫文件自動管理:
sqlplus / as sysdba
alter system set standby_file_management=MANUAL;
清理standby log:
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路徑:
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';
修改完后打開備庫文件自動管理:
sqlplus / as sysdba
alter system set standby_file_management=AUTO;
檢查主備scn是否一致:
sqlplus / as sysdba
col HXFNM for a100
set line222
select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;
主庫切幾次歸檔:
sqlplus / as sysdba
ALTER SYSTEM ARCHIVE LOG CURRENT;
ALTER SYSTEM SWITCH LOGFILE;
開啟備庫應用日志:
sqlplus / as sysdba
alter database open;
alter pluggable database all open;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
查看備庫同步是否正常:
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#;
主庫插入數(shù)據(jù):
sqlplus test/test@pdb01
insert into test values (999);
commit;
備庫查詢是否實時同步:
sqlplus / as sysdba
alter session set container=pdb01;
select * from test.test;
ID
----------
1
2
999
至此,18C的GAP也已修復,可以看到Oracle隨著版本升級,越來越自動化的操作,意味著運維自動化的未來。
參考文檔: