DG模拟GAP手动处理

DG_GAP模拟实验

toc

一、当前环境

Oracle版本:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
IP规划:

序号 IP 主机名 SID 说明
1 192.168.0.50 11g proe primary database
2 192.168.1.50 11gtest stddb physical standby database

其他说明:
DG环境部署完成查询状态

# 主库情况
SYS@proe>select database_role,protection_mode,protection_level from v$database;

DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY          MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE
# 备库情况
SYS@stddb>select database_role,protection_mode,protection_level from v$database;

DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

二、模拟故障发生

1.停止备库应用日志服务

SYS@stddb>alter database recover managed standby database cancel;

Database altered.

2.主库执行一些操作并切换日志,需要多切换几次

# 主库创建两个表并做数据插入
SYS@proe>conn hr/hr
Connected.
HR@proe>create table gaptest1 (id int);
Table created.

HR@proe>insert into gaptest1 (select employee_id from employees);
107 rows created.

HR@proe>create table gaptest2(id int);
Table created.

HR@proe>insert into gaptest2 (select empno from scott.emp);
16 rows created.

# 进行日志切换操作,重复几次
SYS@proe>alter system switch logfile;
System altered.

SYS@proe>/
System altered.

SYS@proe>/
System altered.

3.查看主库和备库的日志状态

# 主库状态
SYS@proe>archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/arch/pridb
Oldest online log sequence     159
Next log sequence to archive   161
Current log sequence           161
# 备库状态
SYS@stddb>archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/arch/stddb
Oldest online log sequence     159
Next log sequence to archive   0
Current log sequence           161

4.备库查询日志应用情况

SYS@stddb>select sequence#,applied from v$archived_log where applied='NO';
 SEQUENCE# APPLIED
---------- ---------
       156 NO
       157 NO
       158 NO
       159 NO
       160 NO

5.删除主备库的158号归档日志

# 主库
[oracle@11g pridb]$ cp 1_158_1045671287.arc 1_158_1045671287.arc.bak
[oracle@11g pridb]$ rm -rf 1_158_1045671287.arc
[oracle@11g pridb]$ rman target /
RMAN> crosscheck archivelog all;
RMAN> delete expired archivelog all;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1715 device type=DISK
List of Archived Log Copies for database with db_unique_name PRIDB
=====================================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
329     1    158     X 22-JUL-20
        Name: /u01/app/oracle/arch/pridb/1_158_1045671287.arc


Do you really want to delete the above objects (enter YES or NO)? yes
deleted archived log
archived log file name=/u01/app/oracle/arch/pridb/1_158_1045671287.arc RECID=329 STAMP=1046448600
Deleted 1 EXPIRED objects
# 备库
[oracle@11gtest stddb]$ cp 1_158_1045671287.arc 1_158_1045671287.arc.bak
[oracle@11gtest stddb]$ rm -rf 1_158_1045671287.arc
RMAN> crosscheck archivelog all;
RMAN> delete expired archivelog all;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=577 device type=DISK
List of Archived Log Copies for database with db_unique_name STDDB
=====================================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
161     1    158     X 22-JUL-20
        Name: /u01/app/oracle/arch/stddb/1_158_1045671287.arc


Do you really want to delete the above objects (enter YES or NO)? yes
deleted archived log
archived log file name=/u01/app/oracle/arch/stddb/1_158_1045671287.arc RECID=161 STAMP=1046207032
Deleted 1 EXPIRED objects 

6.启动备库日志应用

SYS@stddb>alter database recover managed standby database disconnect;

Database altered.
SYS@stddb>select process,status,sequence# from v$managed_standby;

PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CLOSING             159
ARCH      CLOSING             160
ARCH      CONNECTED             0
ARCH      CLOSING             158
RFS       IDLE                  0
RFS       IDLE                  0
RFS       IDLE                161
MRP0      WAIT_FOR_GAP        158 ###!!!可以看到gap已经出现

8 rows selected.

三、进入修复阶段

1.备库停止日志应用

SYS@stddb> alter database recover managed standby database cancel;

Database altered.

2.查看主库对应的缺失归档日志

SYS@proe>select sequence#,first_change# from v$archived_log where sequence#=158;

 SEQUENCE# FIRST_CHANGE#
---------- -------------
       158       2335375
       158       2335375

3.从主库的scn2335375开始进行增量备份

RMAN>  backup incremental from scn 2335375 database format '/home/oracle/gapback/lost_arc_%U';
...
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 22-JUL-20

4.将增量备份传输给备库

[root@11g gapback]# scp ./* 11gtest:/home/oracle/gapback/

5.备库恢复增量备份

SYS@stddb>shutdown immediate;
SYS@stddb>startup mount;
# 恢复增量备份
RMAN> catalog backuppiece '/home/oracle/gapback/lost_arc_2bv5v9mo_1_1';

using target database control file instead of recovery catalog
cataloged backup piece
backup piece handle=/home/oracle/gapback/lost_arc_2bv5v9mo_1_1 RECID=52 STAMP=1046215162

RMAN> catalog backuppiece '/home/oracle/gapback/lost_arc_2cv5v9pd_1_1';

cataloged backup piece
backup piece handle=/home/oracle/gapback/lost_arc_2cv5v9pd_1_1 RECID=53 STAMP=1046215199

RMAN> recover database noredo;

Starting recover at 19-JUL-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=573 device type=DISK
datafile 7 not processed because file is read-only
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/proe/system01.dbf
destination for restore of datafile 00002: /u01/app/oracle/oradata/proe/sysaux01.dbf
destination for restore of datafile 00003: /u01/app/oracle/oradata/proe/undotbs01.dbf
destination for restore of datafile 00004: /u01/app/oracle/oradata/proe/users01.dbf
destination for restore of datafile 00005: /u01/app/oracle/oradata/proe/example01.dbf
destination for restore of datafile 00006: /u01/app/oracle/oradata/proe/test_1.dbf
destination for restore of datafile 00008: /u01/app/oracle/oradata/proe/tbs1.dbf
destination for restore of datafile 00009: /u01/app/oracle/oradata/proe/trans_tbs1.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/gapback/lost_arc_2bv5v9mo_1_1
channel ORA_DISK_1: piece handle=/home/oracle/gapback/lost_arc_2bv5v9mo_1_1 tag=TAG20200722T181344
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

Finished recover at 19-JUL-20

6.主库重新生成一个备库控制文件传给备库

SYS@proe>alter database create standby controlfile as '/home/oracle/gapback/std_contest.ctl';

Database altered.

[root@11g gapback]# scp std_contest.ctl 11gtest:/home/oracle/gapback/

7.备库进行控制文件恢复

SYS@stddb>shutdown immediate;
SYS@stddb>startup nomount;
#恢复控制文件
RMAN> restore controlfile from '/home/oracle/gapback/std_contest.ctl'; 

Starting restore at 19-JUL-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=572 device type=DISK

channel ORA_DISK_1: copied control file copy
output file name=/u01/app/oracle/oradata/stddb/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/stddb/control02.ctl
Finished restore at 19-JUL-20
# 关库重启
RMAN> shutdown immediate;
SYS@stddb>startup;

8.重新启用ADG

SYS@stddb>alter database recover managed standby database using current logfile disconnect;

Database altered.

SYS@stddb> select name,open_mode from v$database;

NAME OPEN_MODE
--------- --------------------
PROD READ ONLY WITH APPLY




原文地址:https://www.cnblogs.com/plutozzl/p/13362883.html