实战篇:Oracle DataGuard 出现 GAP 修复完整步骤

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 实战篇:Oracle DataGuard 出现 GAP 修复完整步骤

前言

DG GAP 顾名思义就是:DG不同步,当备库不能接受到一个或多个主库的归档日志文件时候,就发生了 GAP。


那么,如果遇到GAP如何修复呢?且听我细细道来~


一、介绍

DG GAP 主要分为以下两类情况:

主库归档日志存在,可以通过配置 Fetch Archive Log(FAL) 参数,自动解决归档 GAP。
主库归档日志丢失,需要 人工干预 来修复。


不同 Oracle 版本的 GAP 修复方式也不尽相同,下面分别介绍不同版本的方式!


11G 的处理步骤:

a.在主库上创建一个备库的控制文件

b.以备库的当前SCN号为起点,在主库上做一个增量备份

c.将增量备份拷贝到备库上

d.使用新的控制文件将备库启动到mount状态

e.将增量备份注册到RMAN的catalog,取消备库的恢复应用,恢复增量备份

f.开启备库的恢复进程


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


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


Oracle随着版本的升级,逐渐将步骤缩减,进行封装,18C之后可谓是达到了所谓的一键刷新,恢复DG同步。


二、实战


下面我们通过实验来进行演示如何修复:


  • 11G常规修复
  • 12C新特性(RECOVER … FROM SERVICE)修复
  • 18C新特性(RECOVER STANDBY DATABASE FROM SERVICE)修复

安装测试环境可以使用博主编写的 Oracle 一键安装脚本,同时支持单机和 RAC 集群模式!

开源项目:Install Oracle Database By Scripts!


三、11G常规修复


首先,模拟备库断电,主库切几个最新的归档,然后手工删掉,重新开启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数据库已存在GAP,GAP日志为:32—34。


a.在主库上创建一个备库的控制文件

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


b.以备库的当前SCN号为起点,在主库上做一个增量备份

备库查询当前 scn 号:

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


确认主备GAP期间是否新增数据文件:

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


主库根据备库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;
}


📢 注意: 如果存在新增数据文件,备库恢复时需要先restore新添加的数据文件。


c.将增量备份和控制文件拷贝到备库上

主库拷贝增量备份和控制文件你至备库:

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


📢 注意: 确认备库的磁盘空间是否足够存放。


d.使用新的控制文件将备库启动到mount状态

备库关闭数据库实例,开启至nomount状态:

sqlplus / as sysdba
shutdown immediate
startup nomount


备库恢复新的控制文件:

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


备库开启到mount状态:

alter database mount;


e.增量备份注册到RMAN的catalog,取消日志应用,恢复增量备份

确认备库已关闭DG同步进程:

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


备库rman注册增量备份文件:

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


备库开启恢复增量备份:

recover database noredo;


f.开启备库的恢复进程

备库开启日志同步进程:

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已被修复,以上方式为常规修复方式,各个版本都通用。


四、12C新特性修复


首先,模拟备库断电,主库切几个最新的归档,然后手工删掉,重新开启DG同步。

模拟GAP期间,有数据文件添加的情况:

##主库添加数据文件
alter tablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;


📢 注意: 当前DG数据库已存在GAP,GAP日志为:30—31 。


a.记录备库当前SCN号

备库记录当前 scn 号:

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


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状态:

sqlplus / as sysdba
shutdown immediate
startup nomount


备库通过from service恢复控制文件:

rman target /
restore standby controlfile from service orcl;


备库开启到mount状态:

sqlplus / as sysdba
alter database mount;


d.备库恢复,修复GAP

检查主备GAP期间是否添加数据文件:

sqlplus / as sysdba
select file# from v$datafile where creation_change# > =2600487;
FILE#
----------
13


restore 新添加的数据文件:

rman target /
run
{
SET NEWNAME FOR DATABASE TO '/oradata/ORCL_STBY/%f_%U';
RESTORE DATAFILE 13 FROM SERVICE orcl;
}


由于主备的数据文件目录不一致,需要修改controlfile中数据文件位置:

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切换控制文件中路径,否则报错:

image.png

e.开启备库日志应用,检查同步

  • 检查主备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#;


  • 主库插入数据
sqlplus test/test@pdb01
insert into test values (999);
commit;


  • 备库查询是否实时同步
alter session set container=pdb01;
select * from test.test;
ID
----------
1
2
999


至此,GAP已修复完成,可以发现,12C这个新特性,将一些步骤进行了省略和封装,进一步减少了我们的操作步骤,但是内部的原理仍然是一致的。


五、18C新特性恢复


18C 新特性是在 12C 的基础上,将 RECOVER STANDBY DATABASE 命令与 FROM SERVICE 子句一起使用,以通过对主数据库进行的更改来刷新物理备用数据库。备库可以直接在开启状态进行刷新。


语法:


  • RECOVER STANDBY DATABASE FROM SERVICE primary_db;


首先,模拟备库断电,主库切几个最新的归档,然后手工删掉,重新开启DG同步。

模拟GAP期间,有数据文件添加的情况:

##主库添加数据文件
alter tablespace TEST add datafile '/oradata/ORCL/test02.dbf' size 100M autoextend off;


📢 注意: 当前 DG 数据库已存在 GAP,GAP 日志为:69—70。


a、执行RECOVER STANDBY DATABASE FROM SERVICE刷新备库


下面演示一下,如何使用一行命令在线修复DG GAP:

备库取消日志应用:

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


备库执行修复命令,开始在线刷新备库:

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


方便大家查看,于是记录恢复全过程,通过以上执行过程,可以看到:


  • RECOVER STANDBY DATABASE命令重新启动备用实例。
  • 从主数据库刷新控制文件,并自动重命名数据文件,临时文件和联机日志。
  • 它可以还原添加到主数据库中的新数据文件,并还原到当前时间的备用数据库。


b.备库修改standby log路径

发现刷新过后,备库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;


c.主库切日志,备库开启日志应用

检查主备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#;


主库插入数据:

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随着版本升级,越来越自动化的操作,意味着运维自动化的未来。


参考文档:


  • 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


相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
3月前
|
Oracle 关系型数据库 数据库
手把手教你Oracle DataGuard主备切换(switchover)
手把手教你Oracle DataGuard主备切换(switchover)
425 4
|
6月前
|
运维 Oracle 容灾
Oracle dataguard 容灾技术实战(笔记),教你一种更清晰的Linux运维架构
Oracle dataguard 容灾技术实战(笔记),教你一种更清晰的Linux运维架构
|
3月前
|
Oracle 网络协议 安全
Oracle 11g DataGuard搭建保姆级教程
Oracle 11g DataGuard搭建保姆级教程
174 4
|
3月前
|
Oracle 网络协议 关系型数据库
Oracle DataGuard主备切换之自动切换
Oracle DataGuard主备切换之自动切换
126 2
|
5月前
|
Oracle 关系型数据库 数据库
Oracle 11G数据库安装步骤及截图操作2
Oracle 11G数据库安装步骤及截图操作
60 0
|
5月前
|
Oracle 安全 关系型数据库
Oracle 11G数据库安装步骤及截图操作1
Oracle 11G数据库安装步骤及截图操作
101 0
|
6月前
|
SQL Oracle 前端开发
Oracle效率分析,Github标星25K+超火的前端实战项目
Oracle效率分析,Github标星25K+超火的前端实战项目
|
6月前
|
存储 SQL Oracle
Oracle存储过程与自定义函数的调用:异同与实战场景
【4月更文挑战第19天】Oracle的存储过程与自定义函数各有特色,存储过程用于封装复杂SQL操作,常在批量处理和数据维护中使用,通过CALL或EXECUTE调用;而自定义函数则用于简单计算和查询,返回单一值,可直接在SQL语句中调用。了解两者异同,如返回值方式、调用方式和应用场景,能提升数据库管理效率。实战场景包括:使用存储过程定期清理过期数据,用自定义函数在查询中动态计算字段值。
|
6月前
|
Oracle 关系型数据库 Java
plsql链接远程Oracle数据库步骤
实际工作中,我们往往需要使用 PLSQL Develope 工具连接远程服务器上的 ORACLE 数据库进行管理,但是由于 ORACLE 安装在本地电脑步骤繁琐,并且会耗费电脑的很大一部分资源,因此,我们寻求一种不需要在本地安装 ORACLE 数据库而能直接使用 PLSQL Develope 工具连接到远程服务器 ORACLE 的方法。
103 2
|
6月前
|
Oracle 关系型数据库
oracle 19c 搭建dataguard 简要命令
通过service 完成dg 搭建。
152 0