Oracle 11G DataGuard GAP 修复 (通过主库scn增备恢复)
介绍
DG GAP 顾名思义就是:DG不同步,当备库不能接受到一个或多个主库的归档日志文件时候,就发生了 GAP。
那么,如果遇到GAP如何修复呢?
DG GAP 主要分为以下两类情况:
- 主库归档日志存在,可以通过配置 Fetch Archive Log(FAL) 参数,自动解决归档 GAP;
- 主库归档日志丢失,需要
人工干预
来修复;
不同 Oracle 版本的 GAP 修复方式也不尽相同,下面分别介绍不同版本的方式!
11G 的处理步骤:
- 在主库上创建一个备库的控制文件
- 以备库的当前SCN号为起点,在主库上做一个增量备份
- 将增量备份拷贝到备库上
- 使用新的控制文件将备库启动到mount状态
- 将增量备份注册到RMAN的catalog,取消备库的恢复应用,恢复增量备份
- 开启备库的恢复进程
12C 的新特性(RECOVER ... FROM SERVICE)
19C 的新特性(RECOVER STANDBY DATABASE FROM SERVICE)
Oracle随着版本的升级,逐渐将步骤缩减,进行封装,19C 之后可谓是达到了所谓的一键刷新,恢复DG同步。
11G DG GAP实战
环境准备
以下为测试环境信息:
角色 | 主机名 | IP地址 | 数据库版本 | 实例名 | DB名 | DB_UNIQUE名 | services名 | TNS名 | sys密码 |
---|---|---|---|---|---|---|---|---|---|
主 | hfhsdb | 172.30.21.164 | 11.2.0.4 | hfhsdb | hfhsdb | hfhsdb | hfhsdb | hfhsdb | oracle |
备 | dghfhsdb | 172.30.21.165 | 11.2.0.4 | dghfhsdb | dghfhsdb | dghfhsdb | dghfhsdb | dghfhsdb | oracle |
模拟 GAP 发生
首先,模拟备库断电,主库切几个最新的归档,然后手工删掉,重新开启DG同步。
备库停止 DG 同步进程:
sql
[oracle@dghfhsdb:/home/oracle]$lsnrctl stop #停止监听
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-NOV-2024 20:39:01
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.30.21.165)(PORT=1521)))
The command completed successfully
[oracle@dghfhsdb:/home/oracle]$sqlplus / as sysdba #连接数据库
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 28 20:39:22 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter database recover managed standby database cancel; #停止日志同步
Database altered.
SQL> shu immediate #关闭数据库
Database closed.
Database dismounted.
ORACLE instance shut down.
主库切换多次归档:
sql
[oracle@hfhsdb:/home/oracle]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 28 20:41:52 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> alter system checkpoint;
System altered.
SQL> alter system checkpoint;
System altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 75
Next log sequence to archive 79
Current log sequence 79
SQL>
主库删除最近几个归档日志:
sql
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$ll
total 164640
-rw-r----- 1 oracle oinstall 333312 Nov 28 19:50 o1_mf_1_72_mnjp7v3b_.arc
-rw-r----- 1 oracle oinstall 57344 Nov 28 19:50 o1_mf_1_73_mnjp83z1_.arc
-rw-r----- 1 oracle oinstall 5632 Nov 28 19:50 o1_mf_1_74_mnjp8dy2_.arc
-rw-r----- 1 oracle oinstall 166799872 Nov 28 20:20 o1_mf_1_75_mnjr0wcn_.arc
-rw-r----- 1 oracle oinstall 1376256 Nov 28 20:42 o1_mf_1_76_mnjs8sky_.arc
-rw-r----- 1 oracle oinstall 3584 Nov 28 20:42 o1_mf_1_77_mnjs8yxc_.arc
-rw-r----- 1 oracle oinstall 6144 Nov 28 20:42 o1_mf_1_78_mnjs989v_.arc
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$mv o1_mf_1_77_mnjs8yxc_.arc o1_mf_1_77_mnjs8yxc_.arc.bak
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$mv o1_mf_1_78_mnjs989v_.arc o1_mf_1_78_mnjs989v_.arc.bak
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$ll
total 164640
-rw-r----- 1 oracle oinstall 333312 Nov 28 19:50 o1_mf_1_72_mnjp7v3b_.arc
-rw-r----- 1 oracle oinstall 57344 Nov 28 19:50 o1_mf_1_73_mnjp83z1_.arc
-rw-r----- 1 oracle oinstall 5632 Nov 28 19:50 o1_mf_1_74_mnjp8dy2_.arc
-rw-r----- 1 oracle oinstall 166799872 Nov 28 20:20 o1_mf_1_75_mnjr0wcn_.arc
-rw-r----- 1 oracle oinstall 1376256 Nov 28 20:42 o1_mf_1_76_mnjs8sky_.arc
-rw-r----- 1 oracle oinstall 3584 Nov 28 20:42 o1_mf_1_77_mnjs8yxc_.arc.bak
-rw-r----- 1 oracle oinstall 6144 Nov 28 20:42 o1_mf_1_78_mnjs989v_.arc.bak
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$
备库开启同步进程:
sql
[oracle@dghfhsdb:/home/oracle]$lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-NOV-2024 20:45:57
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /oracle/app/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /oracle/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Log messages written to /oracle/app/oracle/diag/tnslsnr/dghfhsdb/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.30.21.165)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.30.21.165)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 28-NOV-2024 20:45:57
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /oracle/app/oracle/diag/tnslsnr/dghfhsdb/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.30.21.165)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "dghfhsdb" has 1 instance(s).
Instance "dghfhsdb", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@dghfhsdb:/home/oracle]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 28 20:46:04 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 3340451840 bytes
Fixed Size 2257840 bytes
Variable Size 687869008 bytes
Database Buffers 2634022912 bytes
Redo Buffers 16302080 bytes
Database mounted.
Database opened.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL>
主库刷新 DEST 状态:
sql
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 28 20:47:45 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter system set log_archive_dest_state_2=defer;
System altered.
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> alter system checkpoint;
System altered.
SQL>
查看同步情况,是否存在 GAP:
sql
-- 主库执行
set line 1000
col status for a10
col type for a10
col error for a20
col gap_status for a20
col synchronization_status for a30
col recovery_mode for a30
select inst_id,status,DEST_ID,TYPE,ERROR,GAP_STATUS,SYNCHRONIZED,SYNCHRONIZATION_STATUS,RECOVERY_MODE from GV$ARCHIVE_DEST_STATUS where STatus <> 'INACTIVE' and type = 'PHYSICAL';
INST_ID STATUS DEST_ID TYPE ERROR GAP_STATUS SYN SYNCHRONIZATION_STATUS RECOVERY_MODE
---------- ---------- ---------- ---------- ---------- ---------------- --- -------------------------- ------------------------------
1 VALID 2 PHYSICAL UNRESOLVABLE GAP NO CHECK CONFIGURATION MANAGED REAL TIME APPLY
-- 显示 UNRESOLVABLE GAP,意味着无法自行修复,需要人工干预
-- 当前数据库 scn 号
SQL> col CURRENT_SCN for 999999999999999999
SQL> select current_scn from v$database;
CURRENT_SCN
-------------------
1707911
-- 备库执行
SQL> col group# for a30
SQL> select process,thread#,group#,sequence#,status from gv$managed_standby;
PROCESS THREAD# GROUP# SEQUENCE# STATUS
--------- ---------- ------------------------------ ---------- ------------
ARCH 0 N/A 0 CONNECTED
ARCH 0 N/A 0 CONNECTED
ARCH 1 6 80 CLOSING
ARCH 1 6 81 CLOSING
RFS 0 N/A 0 IDLE
RFS 0 N/A 0 IDLE
RFS 0 N/A 0 IDLE
RFS 1 2 82 IDLE
MRP0 1 N/A 77 WAIT_FOR_GAP
9 rows selected.
SQL> select count(*) from gv$archived_log where applied='NO';
COUNT(*)
----------
3
SQL> select * from v$archive_gap;
THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
---------- ------------- --------------
1 77 78
SQL> col CURRENT_SCN for 999999999999999999
SQL> select current_scn from v$database;
CURRENT_SCN
-------------------
1707090
确定主库是否添加数据文件:
sql
SQL> select FILE#,name from v$datafile where CREATION_CHANGE#> =1707090;
no rows selected
注意 当前 ADG 已存在 GAP,并且 GAP 期间主库没有增加数据文件,缺少日志号为 77,78,即是前面模拟断电删除的归档日志文件,已经确认无法找回,需要人工干预进行修复。
常规修复
主库根据备库 scn 号进行增量备份:
sql
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Nov 28 20:59:25 2024
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: HEFEIDB (DBID=955642886)
RMAN> backup incremental from scn 1707090 database format '/backup/incre_%U';
Starting backup at 2024-11-28 21:00:06
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1528 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/oradata/hefeidb/itpux.dbf
input datafile file number=00001 name=/oradata/hefeidb/system01.dbf
input datafile file number=00002 name=/oradata/hefeidb/sysaux01.dbf
input datafile file number=00003 name=/oradata/hefeidb/undotbs01.dbf
input datafile file number=00004 name=/oradata/hefeidb/users01.dbf
input datafile file number=00006 name=/oradata/hefeidb/hsdb1.dbf
channel ORA_DISK_1: starting piece 1 at 2024-11-28 21:00:07
channel ORA_DISK_1: finished piece 1 at 2024-11-28 21:00:42
piece handle=/backup/incre_083b9q6n_1_1 tag=TAG20241128T210007 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 2024-11-28 21:00:44
channel ORA_DISK_1: finished piece 1 at 2024-11-28 21:00:45
piece handle=/backup/incre_093b9q7q_1_1 tag=TAG20241128T210007 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2024-11-28 21:00:45
将增量备份拷贝至备库:
sql
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$scp /backup/incre_0* 172.30.21.165:/backup/
The authenticity of host '172.30.21.165 (172.30.21.165)' can't be established.
ECDSA key fingerprint is SHA256:P1FitT4UKjwoEHe9vJfy/ioPdwoHhdUWAequhuUXvDU.
ECDSA key fingerprint is MD5:8f:6e:9a:0f:1b:1d:53:19:d6:a7:4a:70:51:79:ce:86.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.30.21.165' (ECDSA) to the list of known hosts.
oracle@172.30.21.165's password:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
lost connection
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$scp /backup/incre_0* 172.30.21.165:/backup/
oracle@172.30.21.165's password:
Permission denied, please try again.
oracle@172.30.21.165's password:
incre_083b9q6n_1_1 100% 504KB 18.9MB/s 00:00
incre_093b9q7q_1_1 100% 40MB 42.1MB/s 00:00
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$
备库关闭 DG 同步进程,如果是 ADG 则需要重启数据库到 mount 状态:
sql
[oracle@dghfhsdb:/home/oracle]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 28 21:05:06 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 3340451840 bytes
Fixed Size 2257840 bytes
Variable Size 687869008 bytes
Database Buffers 2634022912 bytes
Redo Buffers 16302080 bytes
Database mounted.
备库 rman 注册增量备份文件:
sql
[oracle@dghfhsdb:/home/oracle]$rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Nov 28 21:06:43 2024
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: HEFEIDB (DBID=955642886, not open)
RMAN> catalog start with '/backup/';
using target database control file instead of recovery catalog
searching for all files that match the pattern /backup/
List of Files Unknown to the Database
=====================================
File Name: /backup/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
File Name: /backup/pdksh-5.2.14-30.x86_64.rpm
File Name: /backup/itpux_table_v4.tar.gz
File Name: /backup/itpux_table_v4.0.dmp
File Name: /backup/itpux_table_v4.0.log
File Name: /backup/itpux_table.log4
File Name: /backup/incre_083b9q6n_1_1
File Name: /backup/incre_093b9q7q_1_1
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /backup/incre_083b9q6n_1_1
File Name: /backup/incre_093b9q7q_1_1
List of Files Which Where Not Cataloged
=======================================
File Name: /backup/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
RMAN-07517: Reason: The file header is corrupted
File Name: /backup/pdksh-5.2.14-30.x86_64.rpm
RMAN-07517: Reason: The file header is corrupted
File Name: /backup/itpux_table_v4.tar.gz
RMAN-07517: Reason: The file header is corrupted
File Name: /backup/itpux_table_v4.0.dmp
RMAN-07517: Reason: The file header is corrupted
File Name: /backup/itpux_table_v4.0.log
RMAN-07517: Reason: The file header is corrupted
File Name: /backup/itpux_table.log4
RMAN-07517: Reason: The file header is corrupted
RMAN> list backup
2> ;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1 Incr 496.00K DISK 00:00:00 2024-11-28 21:00:07
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20241128T210007
Piece Name: /backup/incre_083b9q6n_1_1
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Incr 1708384 2024-11-28 21:00:07 /oradata/hefeidb/system01.dbf
2 Incr 1708384 2024-11-28 21:00:07 /oradata/hefeidb/sysaux01.dbf
3 Incr 1708384 2024-11-28 21:00:07 /oradata/hefeidb/undotbs01.dbf
4 Incr 1708384 2024-11-28 21:00:07 /oradata/hefeidb/users01.dbf
5 Incr 1708384 2024-11-28 21:00:07 /oradata/hefeidb/itpux.dbf
6 Incr 1708384 2024-11-28 21:00:07 /oradata/hefeidb/fghsdb1.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
2 Incr 40.02M DISK 00:00:00 2024-11-28 21:00:42
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20241128T210007
Piece Name: /backup/incre_093b9q7q_1_1
Control File Included: Ckp SCN: 1708569 Ckp time: 2024-11-28 21:00:42
RMAN> recover database noredo;
Starting recover at 2024-11-28 21:11:49
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=15 device type=DISK
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /oradata/hefeidb/system01.dbf
destination for restore of datafile 00002: /oradata/hefeidb/sysaux01.dbf
destination for restore of datafile 00003: /oradata/hefeidb/undotbs01.dbf
destination for restore of datafile 00004: /oradata/hefeidb/users01.dbf
destination for restore of datafile 00005: /oradata/hefeidb/itpux.dbf
destination for restore of datafile 00006: /oradata/hefeidb/fghsdb1.dbf
channel ORA_DISK_1: reading from backup piece /backup/incre_083b9q6n_1_1
channel ORA_DISK_1: piece handle=/backup/incre_083b9q6n_1_1 tag=TAG20241128T210007
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished recover at 2024-11-28 21:11:51
在主库上创建一个备库的控制文件:
sql
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 28 21:13:58 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter database create standby controlfile as '/backup/oradb_standby241128.ctl';
Database altered.
将生成的控制文件拷贝到备库:
sql
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$scp /backup/oradb_standby241128.ctl 172.30.21.165:/backup
oracle@172.30.21.165's password:
oradb_standby241128.ctl 100% 40MB 54.0MB/s 00:00
[oracle@hfhsdb:/archive/HFHSDB/archivelog/2024_11_28]$
备库关闭数据库实例,开启至 nomount 状态:
sql
[oracle@dghfhsdb:/backup]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 28 21:15:46 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 3340451840 bytes
Fixed Size 2257840 bytes
Variable Size 687869008 bytes
Database Buffers 2634022912 bytes
Redo Buffers 16302080 bytes
SQL>
备库恢复新的控制文件:
sql
[oracle@dghfhsdb:/backup]$rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Nov 28 21:17:09 2024
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: HEFEIDB (not mounted)
RMAN> restore standby controlfile from '/backup/oradb_standby241128.ctl';
Starting restore at 2024-11-28 21:17:22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1521 device type=DISK
channel ORA_DISK_1: copied control file copy
output file name=/oradata/hefeidb/control01.ctl
output file name=/oradata/hefeidb/control02.ctl
Finished restore at 2024-11-28 21:17:23
RMAN>
备库开启到 mount 状态:
sql
[oracle@dghfhsdb:/backup]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 28 21:17:59 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> alter database mount;
Database altered.
-----------------------------------------------------------------------------------------------
## 如果主备库数据文件路径不一致,备库控制文件需要注册数据文件,如果一样,可以不操作
RMAN> catalog start with '/oradata/ORADBDG/datafile/';
searching for all files that match the pattern /oradata/ORADBDG/datafile/
List of Files Unknown to the Database
=====================================
File Name: /oradata/ORADBDG/datafile/o1_mf_system_kzrsshwr_.dbf
File Name: /oradata/ORADBDG/datafile/o1_mf_sysaux_kzrst97y_.dbf
File Name: /oradata/ORADBDG/datafile/o1_mf_undotbs1_kzrstrhg_.dbf
File Name: /oradata/ORADBDG/datafile/o1_mf_users_kzrstzhx_.dbf
File Name: /oradata/ORADBDG/datafile/o1_mf_temp_kzrsxdq5_.tmp
File Name: /oradata/ORADBDG/datafile/o1_mf_system_kzrt67q4_.dbf
Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /oradata/ORADBDG/datafile/o1_mf_system_kzrsshwr_.dbf
File Name: /oradata/ORADBDG/datafile/o1_mf_sysaux_kzrst97y_.dbf
File Name: /oradata/ORADBDG/datafile/o1_mf_undotbs1_kzrstrhg_.dbf
File Name: /oradata/ORADBDG/datafile/o1_mf_users_kzrstzhx_.dbf
File Name: /oradata/ORADBDG/datafile/o1_mf_temp_kzrsxdq5_.tmp
File Name: /oradata/ORADBDG/datafile/o1_mf_system_kzrt67q4_.dbf
RMAN> switch database to copy;
datafile 1 switched to datafile copy "/oradata/ORADBDG/datafile/o1_mf_system_kzrsshwr_.dbf"
datafile 3 switched to datafile copy "/oradata/ORADBDG/datafile/o1_mf_sysaux_kzrst97y_.dbf"
datafile 4 switched to datafile copy "/oradata/ORADBDG/datafile/o1_mf_undotbs1_kzrstrhg_.dbf"
datafile 5 switched to datafile copy "/oradata/ORADBDG/datafile/o1_mf_system_kzrt67q4_.dbf"
datafile 7 switched to datafile copy "/oradata/ORADBDG/datafile/o1_mf_users_kzrstzhx_.dbf"
---------------------------------------------------------------------------------------
##路径如果一致的话,之间open数据库
SQL> alter database open;
Database altered.
备库开启日志同步进程:
sql
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
sql
set line 1000
col status for a10
col type for a10
col error for a20
col gap_status for a20
col synchronization_status for a30
col recovery_mode for a30
select inst_id,status,DEST_ID,TYPE,ERROR,GAP_STATUS,SYNCHRONIZED,SYNCHRONIZATION_STATUS,RECOVERY_MODE from GV$ARCHIVE_DEST_STATUS where STatus <> 'INACTIVE' and type = 'PHYSICAL';
INST_ID STATUS DEST_ID TYPE ERROR GAP_STATUS SYN SYNCHRONIZATION_STATUS RECOVERY_MODE
---------- ---------- ---------- ---------- ---------- ----------------- --- ----------------------------- ------------------------------
1 VALID 2 PHYSICAL NO GAP NO CHECK CONFIGURATION MANAGED REAL TIME APPLY
-- 显示 NO GAP,同步正常
SQL> col group# for a30
SQL> select process,thread#,group#,sequence#,status from gv$managed_standby;
PROCESS THREAD# GROUP# SEQUENCE# STATUS
--------- ---------- ------------------------------ ---------- ------------
ARCH 0 N/A 0 CONNECTED
ARCH 0 N/A 0 CONNECTED
ARCH 1 8 84 CLOSING
ARCH 0 N/A 0 CONNECTED
RFS 0 N/A 0 IDLE
RFS 0 N/A 0 IDLE
RFS 1 5 85 IDLE
RFS 0 N/A 0 IDLE
MRP0 1 N/A 85 APPLYING_LOG
9 rows selected.
SQL> select count(*) from gv$archived_log where applied='NO';
COUNT(*)
----------
0
SQL> select * from v$archive_gap;
no rows selected
至此,DG GAP已被修复,以上方式为常规修复方式,各个版本都通用。