日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

實(shí)戰(zhàn)篇:Oracle DataGuard 出現(xiàn) GAP 修復(fù)完整步驟

 LuciferLiu 2021-12-10

前言

DG GAP 顧名思義就是:DG不同步,當(dāng)備庫(kù)不能接受到一個(gè)或多個(gè)主庫(kù)的歸檔日志文件時(shí)候,就發(fā)生了 GAP。

那么,如果遇到GAP如何修復(fù)呢?且聽(tīng)我細(xì)細(xì)道來(lái)~

一、介紹

DG GAP 主要分為以下兩類(lèi)情況:

1、主庫(kù)歸檔日志存在,可以通過(guò)配置 Fetch Archive Log(FAL) 參數(shù),自動(dòng)解決歸檔 GAP。
2、主庫(kù)歸檔日志丟失,需要 人工干預(yù) 來(lái)修復(fù)。

不同 Oracle 版本的 GAP 修復(fù)方式也不盡相同,下面分別介紹不同版本的方式!

11G 的處理步驟:

a.在主庫(kù)上創(chuàng)建一個(gè)備庫(kù)的控制文件
b.以備庫(kù)的當(dāng)前SCN號(hào)為起點(diǎn),在主庫(kù)上做一個(gè)增量備份
c.將增量備份拷貝到備庫(kù)上
d.使用新的控制文件將備庫(kù)啟動(dòng)到mount狀態(tài)
e.將增量備份注冊(cè)到RMAN的catalog,取消備庫(kù)的恢復(fù)應(yīng)用,恢復(fù)增量備份
f.開(kāi)啟備庫(kù)的恢復(fù)進(jìn)程

12C 的新特性(RECOVER … FROM SERVICE)

18C 的新特性(RECOVER STANDBY DATABASE FROM SERVICE)

Oracle隨著版本的升級(jí),逐漸將步驟縮減,進(jìn)行封裝,18C之后可謂是達(dá)到了所謂的一鍵刷新,恢復(fù)DG同步。

二、實(shí)戰(zhàn)

下面我們通過(guò)實(shí)驗(yàn)來(lái)進(jìn)行演示如何修復(fù):

  • 11G常規(guī)修復(fù)
  • 12C新特性(RECOVER … FROM SERVICE)修復(fù)
  • 18C新特性(RECOVER STANDBY DATABASE FROM SERVICE)修復(fù)

安裝測(cè)試環(huán)境可以使用博主編寫(xiě)的 Oracle 一鍵安裝腳本,同時(shí)支持單機(jī)和 RAC 集群模式!

開(kāi)源項(xiàng)目:Install Oracle Database By Scripts!

更多更詳細(xì)的腳本使用方式可以訂閱專欄:Oracle一鍵安裝腳本。

三、11G常規(guī)修復(fù)

首先,模擬備庫(kù)斷電,主庫(kù)切幾個(gè)最新的歸檔,然后手工刪掉,重新開(kāi)啟DG同步。

備庫(kù)停止DG同步進(jìn)程:

sqlplus / as sysdba
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
shutdown immediate

主庫(kù)切換多次歸檔:

sqlplus / as sysdba
alter system switch logfile;

主庫(kù)刪除最近幾個(gè)歸檔日志:

rm 1_34_1070147137.arc 
rm 1_33_1070147137.arc

備庫(kù)開(kāi)啟同步進(jìn)程:

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

📢 注意: 當(dāng)前DG數(shù)據(jù)庫(kù)已存在GAP,GAP日志為:32—34。

a.在主庫(kù)上創(chuàng)建一個(gè)備庫(kù)的控制文件

alter database create standby controlfile as '/tmp/standby.ctl';

b.以備庫(kù)的當(dāng)前SCN號(hào)為起點(diǎn),在主庫(kù)上做一個(gè)增量備份

備庫(kù)查詢當(dāng)前 scn 號(hào):

sqlplus / as sysdba
select  to_char(current_scn) from v$database;
TO_CHAR(CURRENT_SCN)
----------------------------------------
1086639

確認(rèn)主備GAP期間是否新增數(shù)據(jù)文件:

sqlplus / as sysdba
select file# from v$datafile where creation_change# > =1086639;

主庫(kù)根據(jù)備庫(kù)scn號(hào)進(jìn)行增量備份:

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ù)文件,備庫(kù)恢復(fù)時(shí)需要先restore新添加的數(shù)據(jù)文件。

c.將增量備份和控制文件拷貝到備庫(kù)上

主庫(kù)拷貝增量備份和控制文件你至備庫(kù):

scp incre_0* oracle@orcl_stby:/home/oracle
scp standby.ctl oracle@orcl_stby:/home/oracle

📢 注意: 確認(rèn)備庫(kù)的磁盤(pán)空間是否足夠存放。

d.使用新的控制文件將備庫(kù)啟動(dòng)到mount狀態(tài)

備庫(kù)關(guān)閉數(shù)據(jù)庫(kù)實(shí)例,開(kāi)啟至nomount狀態(tài):

sqlplus / as sysdba
shutdown immediate
startup nomount

備庫(kù)恢復(fù)新的控制文件:

rman target /
restore controlfile from '/home/oracle/standby.ctl';

備庫(kù)開(kāi)啟到mount狀態(tài):

alter database mount;

e.增量備份注冊(cè)到RMAN的catalog,取消日志應(yīng)用,恢復(fù)增量備份

確認(rèn)備庫(kù)已關(guān)閉DG同步進(jìn)程:

sqlplus / as sysdba
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

備庫(kù)rman注冊(cè)增量備份文件:

rman target /
catalog start with '/home/oracle/';
YES

備庫(kù)開(kāi)啟恢復(fù)增量備份:

recover database noredo;

f.開(kāi)啟備庫(kù)的恢復(fù)進(jìn)程

備庫(kù)開(kāi)啟日志同步進(jìn)程:

sqlplus / as sysdba
alter database open read only;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;

主庫(kù)重新激活同步:

sqlplus / as sysdba
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=defer;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=enable;

查詢是否存在GAP,確認(rèn)主備是否同步:

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已被修復(fù),以上方式為常規(guī)修復(fù)方式,各個(gè)版本都通用。

四、12C新特性修復(fù)

首先,模擬備庫(kù)斷電,主庫(kù)切幾個(gè)最新的歸檔,然后手工刪掉,重新開(kāi)啟DG同步。

模擬GAP期間,有數(shù)據(jù)文件添加的情況:

##主庫(kù)添加數(shù)據(jù)文件
alter tablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;

📢 注意: 當(dāng)前DG數(shù)據(jù)庫(kù)已存在GAP,GAP日志為:30—31 。

a.記錄備庫(kù)當(dāng)前SCN號(hào)

備庫(kù)記錄當(dāng)前 scn 號(hào):

sqlplus / as sysdba
SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
2600487

b.使用recover standby using service恢復(fù)

采用rman的新功能,recover standby using service,通過(guò)RMAN連接到target備庫(kù),然后用主庫(kù)的service執(zhí)行恢復(fù)備庫(kù)命令。

語(yǔ)法:

RECOVER DATABASE FROM SERVICE < PRIMARY DB SERVICE NAME > NOREDO USING COMPRESSED BACKUPSET;

📢 注意: 確認(rèn)主庫(kù)的TNS已配置,這里的< PRIMARY DB SERVICE NAME >即 TNSNAME。

c.備庫(kù)啟動(dòng)到nomount狀態(tài),恢復(fù)控制文件

備庫(kù)啟動(dòng)到nomount狀態(tài):

sqlplus / as sysdba
shutdown immediate
startup nomount

備庫(kù)通過(guò)from service恢復(fù)控制文件:

rman target /
restore standby controlfile from service orcl;

備庫(kù)開(kāi)啟到mount狀態(tài):

sqlplus / as sysdba
alter database mount;

d.備庫(kù)恢復(fù),修復(fù)GAP

檢查主備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;

將備庫(kù)文件管理方式改為手動(dòng):

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';

備庫(kù)重命名完后再改為自動(dòng):

sqlplus / as sysdba
alter system set standby_file_management=AUTO;

恢復(fù)主備GAP:

recover database from service orcl noredo using compressed backupset;

📢 注意: 如果主備庫(kù)文件目錄不一致,則需要catalog切換控制文件中路徑,否則報(bào)錯(cuò):

e.開(kāi)啟備庫(kù)日志應(yīng)用,檢查同步

  • 檢查主備scn是否一致
sqlplus / as sysdba
col HXFNM for a100
set line222
select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;
  • 主庫(kù)切幾次歸檔
sqlplus / as sysdba
ALTER SYSTEM ARCHIVE LOG CURRENT;
ALTER SYSTEM SWITCH LOGFILE;
  • 開(kāi)啟備庫(kù)應(yīng)用日志
sqlplus / as sysdba
alter database open;
alter pluggable database all open;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
  • 查看備庫(kù)同步是否正常
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#;
  • 主庫(kù)插入數(shù)據(jù)
sqlplus test/test@pdb01
insert into test values (999);
commit;
  • 備庫(kù)查詢是否實(shí)時(shí)同步
alter session set container=pdb01;
select * from test.test;
ID
----------
1
2
999

至此,GAP已修復(fù)完成,可以發(fā)現(xiàn),12C這個(gè)新特性,將一些步驟進(jìn)行了省略和封裝,進(jìn)一步減少了我們的操作步驟,但是內(nèi)部的原理仍然是一致的。

五、18C新特性恢復(fù)

18C 新特性是在 12C 的基礎(chǔ)上,將 RECOVER STANDBY DATABASE 命令與 FROM SERVICE 子句一起使用,以通過(guò)對(duì)主數(shù)據(jù)庫(kù)進(jìn)行的更改來(lái)刷新物理備用數(shù)據(jù)庫(kù)。備庫(kù)可以直接在開(kāi)啟狀態(tài)進(jìn)行刷新。

語(yǔ)法:

RECOVER STANDBY DATABASE FROM SERVICE primary_db;

首先,模擬備庫(kù)斷電,主庫(kù)切幾個(gè)最新的歸檔,然后手工刪掉,重新開(kāi)啟DG同步。

模擬GAP期間,有數(shù)據(jù)文件添加的情況:

##主庫(kù)添加數(shù)據(jù)文件
alter tablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;

📢 注意: 當(dāng)前 DG 數(shù)據(jù)庫(kù)已存在 GAP,GAP 日志為:69—70。

a、執(zhí)行RECOVER STANDBY DATABASE FROM SERVICE刷新備庫(kù)

下面演示一下,如何使用一行命令在線修復(fù)DG GAP:

備庫(kù)取消日志應(yīng)用:

sqlplus / as sysdba
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

備庫(kù)執(zhí)行修復(fù)命令,開(kāi)始在線刷新備庫(kù):

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

方便大家查看,于是記錄恢復(fù)全過(guò)程,通過(guò)以上執(zhí)行過(guò)程,可以看到:

  • RECOVER STANDBY DATABASE命令重新啟動(dòng)備用實(shí)例。
  • 從主數(shù)據(jù)庫(kù)刷新控制文件,并自動(dòng)重命名數(shù)據(jù)文件,臨時(shí)文件和聯(lián)機(jī)日志。
  • 它可以還原添加到主數(shù)據(jù)庫(kù)中的新數(shù)據(jù)文件,并還原到當(dāng)前時(shí)間的備用數(shù)據(jù)庫(kù)。

b.備庫(kù)修改standby log路徑

發(fā)現(xiàn)刷新過(guò)后,備庫(kù)redo log路徑已修改,standby log路徑未修改,因此手動(dòng)修改。

查詢備庫(kù)的日志文件路徑:

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

關(guān)閉備庫(kù)文件自動(dòng)管理:

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';

修改完后打開(kāi)備庫(kù)文件自動(dòng)管理:

sqlplus / as sysdba
alter system set standby_file_management=AUTO;

c.主庫(kù)切日志,備庫(kù)開(kāi)啟日志應(yīng)用

檢查主備scn是否一致:

sqlplus / as sysdba
col HXFNM for a100
set line222
select HXFIL File_num,substr(HXFNM,1,40) HXFNM,fhscn from x$kcvfh;

主庫(kù)切幾次歸檔:

sqlplus / as sysdba
ALTER SYSTEM ARCHIVE LOG CURRENT;
ALTER SYSTEM SWITCH LOGFILE;

開(kāi)啟備庫(kù)應(yīng)用日志:

sqlplus / as sysdba
alter database open;
alter pluggable database all open;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;

查看備庫(kù)同步是否正常:

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#;

主庫(kù)插入數(shù)據(jù):

sqlplus test/test@pdb01
insert into test values (999);
commit;

備庫(kù)查詢是否實(shí)時(shí)同步:

sqlplus / as sysdba
alter session set container=pdb01;
select * from test.test;
ID
----------
1
2
999

至此,18C的GAP也已修復(fù),可以看到Oracle隨著版本升級(jí),越來(lái)越自動(dòng)化的操作,意味著運(yùn)維自動(dòng)化的未來(lái)。

參考文檔:

  • RESTORE/Recover from Service
  • Restoring and Recovering Files Over the Network(DG)
  • Restoring and Recovering Files Over the Network(RMAN)
  • Rolling Forward a Standby With One Command 18C

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多