数据库
首页 > 数据库> > oracle 11g ADG GAP修复

oracle 11g ADG GAP修复

作者:互联网

一、模拟产生GAP
1.备库停止DG同步进程:
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/archive
Oldest online log sequence     72
Next log sequence to archive   0
Current log sequence           74

SQL> alter database recover managed standby database cancel;

Database altered.

SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

2.主库切换多次归档:
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/archive
Oldest online log sequence     72
Next log sequence to archive   74
Current log sequence           74
SQL>
SQL>
SQL>
SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/archive
Oldest online log sequence     76
Next log sequence to archive   78
Current log sequence           78

3.主库删除/移动最近几个归档日志:
[oracle@dgdb1 ~]$ cd /oracle/archive/
[oracle@dgdb1 archive]$ mv 1_74_1024761634.dbf 1_75_1024761634.dbf 1_76_1024761634.dbf 1_77_1024761634.dbf /home/oracle

4.备库开启同步进程:
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.


5.查看GAP:
SQL> select * from v$archive_gap;

   THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
---------- ------------- --------------
         1            73             77
		 
SQL> SELECT max(sequence#) from v$archived_log where applied='YES';

MAX(SEQUENCE#)
--------------
            73
丢失了74-77四个日志


二、恢复备库:
1.在主库上创建一个备库的控制文件:
SQL> alter database create standby controlfile as '/home/oracle/standby.ctl';

Database altered.

2.以备库的当前SCN号为起点,在主库上做一个增量备份
查询备库当前SCN:
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
    1248633
	
确认主备GAP期间是否新增数据文件:
SQL> select file# from v$datafile where creation_change# > =1248633;
如果存在新增数据文件,备库恢复时需要先restore新添加的数据文件。

主库根据备库scn号进行增量备份:
RMAN> run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup INCREMENTAL from scn 1248633 database format '/home//oracle/incre_%U';
release channel c1;
release channel c2;
}
2> 3> 4> 5> 6> 7>
allocated channel: c1
channel c1: SID=52 device type=DISK

allocated channel: c2
channel c2: SID=54 device type=DISK

Starting backup at 10-MAY-22
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/rmanpri/system01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/rmanpri/users01.dbf
channel c1: starting piece 1 at 10-MAY-22
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/rmanpri/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/rmanpri/undotbs01.dbf
channel c2: starting piece 1 at 10-MAY-22
channel c2: finished piece 1 at 10-MAY-22
piece handle=/home/oracle/incre_0u0t5vb9_1_1 tag=TAG20220510T185433 comment=NONE
channel c2: backup set complete, elapsed time: 00:01:06
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
including current control file in backup set
channel c2: starting piece 1 at 10-MAY-22
channel c2: finished piece 1 at 10-MAY-22
piece handle=/home/oracle/incre_0v0t5vdb_1_1 tag=TAG20220510T185433 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:01
channel c1: finished piece 1 at 10-MAY-22
piece handle=/home/oracle/incre_0t0t5vb9_1_1 tag=TAG20220510T185433 comment=NONE
channel c1: backup set complete, elapsed time: 00:01:10
Finished backup at 10-MAY-22

released channel: c1

released channel: c2



[oracle@dgdb1 trace]$ ll /home/oracle/
total 20404
-rw-r----- 1 oracle oinstall   221184 May 10 18:55 incre_0t0t5vb9_1_1
-rw-r----- 1 oracle oinstall   344064 May 10 18:55 incre_0u0t5vb9_1_1
-rw-r----- 1 oracle oinstall 10092544 May 10 18:55 incre_0v0t5vdb_1_1
-rw-r----- 1 oracle oinstall 10043392 May 10 18:48 standby.ctl


将增量备份和控制文件拷贝到备库上:
[oracle@dgdb1 trace]$ scp /home/oracle/incre_0* dgdb2:/home/oracle
oracle@dgdb2's password:
incre_0t0t5vb9_1_1                                                                                                              100%  216KB 216.0KB/s   00:00
incre_0u0t5vb9_1_1                                                                                                              100%  336KB 336.0KB/s   00:00
incre_0v0t5vdb_1_1                                                                                                              100% 9856KB   9.6MB/s   00:01
[oracle@dgdb1 trace]$ scp /home/oracle/standby.ctl dgdb2:/home/oracle
oracle@dgdb2's password:
standby.ctl

[oracle@dgdb2 trace]$ ll /home/oracle/
total 20216
-rw-r----- 1 oracle oinstall   221184 May 11 17:49 incre_0t0t5vb9_1_1
-rw-r----- 1 oracle oinstall   344064 May 11 17:49 incre_0u0t5vb9_1_1
-rw-r----- 1 oracle oinstall 10092544 May 11 17:49 incre_0v0t5vdb_1_1
-rw-r----- 1 oracle oinstall 10043392 May 11 17:50 standby.ctl

备库关闭数据库实例,开启至nomount状态:
SQL> alter database recover managed standby database cancel;

Database altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area  584568832 bytes
Fixed Size                  2255432 bytes
Variable Size             226493880 bytes
Database Buffers          352321536 bytes
Redo Buffers                3497984 bytes

备库恢复新的控制文件:
RMAN> restore controlfile from '/home/oracle/standby.ctl';

Starting restore at 11-MAY-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: copied control file copy
output file name=/u01/app/oracle/oradata/rmanstd/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/rmanstd/control02.ctl
Finished restore at 11-MAY-22

备库开启到mount状态:
SQL> alter database mount;

Database altered.

确认取消日志应用:
SQL> alter database recover managed standby database cancel;

Database altered.

增量备份注册到RMAN的catalog:
RMAN> catalog start with '/home/oracle';

released channel: ORA_DISK_1
Starting implicit crosscheck backup at 11-MAY-22
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
Crosschecked 9 objects
Finished implicit crosscheck backup at 11-MAY-22

Starting implicit crosscheck copy at 11-MAY-22
using channel ORA_DISK_1
Crosschecked 4 objects
Finished implicit crosscheck copy at 11-MAY-22

searching for all files in the recovery area
cataloging files...
no files cataloged

searching for all files that match the pattern /home/oracle

List of Files Unknown to the Database
=====================================
File Name: /home/oracle/.bashrc
File Name: /home/oracle/.bash_logout
File Name: /home/oracle/incre_0v0t5vdb_1_1
File Name: /home/oracle/.bash_history
File Name: /home/oracle/.oracle/logs/installActions2019-11-04_11-00-39AM.log
File Name: /home/oracle/.oracle/logs/oraInstall2019-11-04_11-00-39AM.out
File Name: /home/oracle/.oracle/logs/oraInstall2019-11-04_11-00-39AM.err
File Name: /home/oracle/.bash_profile
File Name: /home/oracle/incre_0u0t5vb9_1_1
File Name: /home/oracle/incre_0t0t5vb9_1_1
File Name: /home/oracle/.kshrc
File Name: /home/oracle/standby.ctl
File Name: /home/oracle/.viminfo

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /home/oracle/incre_0v0t5vdb_1_1
File Name: /home/oracle/incre_0u0t5vb9_1_1
File Name: /home/oracle/incre_0t0t5vb9_1_1
File Name: /home/oracle/standby.ctl

备库开启恢复增量备份:
RMAN> recover database noredo;

Starting recover at 11-MAY-22
using channel ORA_DISK_1
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: /u01/app/oracle/oradata/rmanstd/system01.dbf
destination for restore of datafile 00004: /u01/app/oracle/oradata/rmanstd/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/incre_0t0t5vb9_1_1
channel ORA_DISK_1: piece handle=/home/oracle/incre_0t0t5vb9_1_1 tag=TAG20220510T185433
channel ORA_DISK_1: restored backup piece 1
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: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /u01/app/oracle/oradata/rmanstd/sysaux01.dbf
destination for restore of datafile 00003: /u01/app/oracle/oradata/rmanstd/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/incre_0u0t5vb9_1_1
channel ORA_DISK_1: piece handle=/home/oracle/incre_0u0t5vb9_1_1 tag=TAG20220510T185433
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

Finished recover at 11-MAY-22

备库开启日志同步进程:
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

查看GAP:
SQL> select * from v$archive_gap;

no rows selected


SQL> SELECT max(sequence#) from v$archived_log where applied='YES';

MAX(SEQUENCE#)
--------------


主库:
SQL> alter system switch logfile;

System altered.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/archive
Oldest online log sequence     79
Next log sequence to archive   81
Current log sequence           81

备库:
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /oracle/archive
Oldest online log sequence     79
Next log sequence to archive   0
Current log sequence           81

GAP修复完成。

  

标签:11g,log,ADG,incre,SQL,oracle,home,channel
来源: https://www.cnblogs.com/orcl-2018/p/16286077.html