本篇文档:
讲述DG环境出现GAP归档缝隙,且主库的该归档日志被删除的情况下,快速恢复DG的连通性
流程讲述:
>明确主库增量备份起点 scn 查询备库控制文件current scn ,及v$datafile_header 数据文件最小scn,两种scn对比选取最小值
>查询主备之间数据文件是否存在不一致 查询主库是否在备库未应用的时间点存在新建数据文件操作,如有新建数据文件操作,需要记录是什么文件
>主库进行增量备份 选择备份起点scn,进行增量备份,且备份standby controlfile控制文件 在本次实验环境中,由于空间文件,需要对主库删除一些历史归档,
但是delete提示归档文件未传输至备库,无法删除,加上force参数 or 操作系统rm删除,检测删除,
本次采用rman 删除 DELETE noprompt force ARCHIVELOG ALL COMPLETED BEFORE ‘SYSDATE-1‘;
>主库备份片传输至备库
>备库restore应用主库传输过来的最新standby控制文件
>备库启动到mount状态 需要注意,当主库新建的数据文件路径,在备库参数文件db_file_name_convert转换参数未完整转换,
可能出现备库查询数据文件的目录结构存在与主库一致的情况,需要及时调整,调整后重启备库至mount状态,
备库的数据文件目录是默认主库的数据文件目录,当存在convert转换参数时,符合条件情况,控制文件会自动转换记录的数据文件目录
>当主备之间数据文件数量存在不一致,需要此步骤 对主备不一致的数据文件,
进行单独还原,restore,因为备库都没有改数据文件,因此直接recover会报错,
需要先restore构建新的数据文件
run{
set newname for datafile 6 to ‘/picclife/app/oracle/oradata/dage/ceshi.dbf‘;
set newname for datafile 7 to ‘/picclife/app/oracle/oradata/dage/ces01.dbf‘;
set newname for datafile 8 to ‘/picclife/app/oracle/oradata/dage/ua01.dbf‘;
restore datafile 6,7,8;
}
>对整个备库,进行recover database noredo操作
因为默认情况下recover database会应用archive+ current logfile,
但是备库的current logfile明显不可用,因此此设置 由于主备之间数据文件目录不同,因此可能需要转换操作,转换命令
: select ‘set newname for datafile ‘||file#||‘ to ‘‘‘||name||‘‘‘;‘ from v$datafile;
run{ set newname for datafile 1 to ‘/picclife/app/oracle/oradata/dage/system01.dbf‘;
... recover database noredo;}
>测试dg的连通性,及mrp进程应用情况验证,实验完毕
[email protected] >ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
SYS > select max(sequence#),thread# from v$archived_log group by thread#;
[email protected] >select max(sequence#),thread# from v$archived_log group by thread#;
主 SYS > alter system switch logfile; select max(sequence#),thread# from v$archived_log group by thread
# select process,client_process,sequence#,status,BLOCK#,BLOCKS from v$managed_standby;
操作
1.0 验证主备DG关系 --主库信息
SYS > select dbid,name, database_role,open_mode,FLASHBACK_ON from v$database;
DBID NAME DATABASE_ROL OPEN_MODE FLASHBACK_ON
----------- --------------- ------------ ---------- ------------------
754170409 ENMO PRIMARY READ WRITE NO
--备库信息
[email protected] >select dbid,name, database_role,open_mode,FLASHBACK_ON from v$database;
DBID NAME DATABASE_ROLE OPEN_MODE FLASHBACK_ON
---------- --------- ---------------- -------------------- ------------------
754170409 ENMO PHYSICAL STANDBY READ ONLY NO
1.1查询备库缺失归档日志
--查询主库最新的归档文件
SYS > select max(sequence#),thread# from v$archived_log group by thread#;
MAX(SEQUENCE#) THREAD# -------------- ----------
997 1
--查询备库记录的最新的归档文件
[email protected] >select max(sequence#),thread# from v$archived_log group by thread#;
MAX(SEQUENCE#) THREAD# -------------- ----------
753 1
--备库查询,出现GAP
[email protected] >select * from v$archive_gap;
THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
---------- ------------- --------------
1 594 594
--查询主库的归档文件--不存在
SYS > select name from v$archived_log where sequence#=594;
NAME
---------------
1.2查询主备之间数据是否存在不一致
--两种方式
A查询v$datafile对比,
B查询备库缺失的GAP FIRST_CHANGE# scn > 数据文件creation_change not null
A--查询发现主库多了三个数据文件--但是此方式不太专业,但胜在简便
SYS > select count(*) from v$datafile;
8
[email protected] >select count(*) from v$datafile;
5
B--查询creted_change --查询备库缺失的GAP归档日志起始SCN号
SYS > select FIRST_CHANGE#,NEXT_CHANGE# from v$archived_log where sequence#=594;
FIRST_CHANGE# NEXT_CHANGE#
------------- ------------
5179446 5182787
查询主库是否在备库GAP的时间节点后,是否新建数据文件
SYS > select file#,name from v$datafile where CREATION_CHANGE#>=5179446;
FILE# NAME
---------- ---------------
6 /home/oracle/ceshi.dbf
7 /home/oracle/ces01.dbf
8 /u01/app/oracle/oradata/ENMO/ua01.dbf --当前实验环境存在主库增加数据文件,需要关注
1.3查询备库最小的SCN号,作为主库增倍的SCN起点!!!
--备库查询控制文件current scn
[email protected] >select CURRENT_SCN from v$database;
CURRENT_SCN
-----------
5179445
--查询数据文件头部最小的SCN号
[email protected] >select min(CHECKPOINT_CHANGE#) from v$datafile_header;
MIN(CHECKPOINT_CHANGE#)
-----------------------
5179446
==可以得出,最小的SCN是控制文件记录的SCN = 5179445
2.0对主库进行增量备份 -对主库进行增量备份,
备份的起始点是之前查询的备库最小SCN号 --备份原则:增量备份1级,属于差异备份,
且备份全库 --备份一个standby controlfile文件 BACKUP INCREMENTAL FROM SCN 5179445 DATABASE FORMAT ‘/tmp/ForStandby_%U‘ tag ‘FORSTANDBY‘;
2.1主库备份一个最新的standby controlfile RMAN> backup current controlfile for standby format ‘/tmp/stdby.ctl‘;
2.2主库的备份片传输至备库,注册,
并将备库使用主库最新的standby controlfile启动到Mount状态
[[email protected] ~]$ scp /tmp/stdby.ctl 192.168.20.66:/tmp/.
--使用主库传输的最新standby controlfile启动到Mount阶段
RMAN> startup nomount;
RMAN> restore standby controlfile from ‘/tmp/stdby.ctl‘;
RMAN> shutdown abort;
RMAN> startup mount; --由于使用新的控制文件,因此需要重新注册备份片
A--目录注册RMAN> catalog start with ‘/tmp/‘;
B--无法使用目录注册备份片,可使用如下方式单独注册
RMAN> catalog backuppiece ‘/tmp/ForStandby_3st1tqco_1_1‘;
RMAN> catalog backuppiece ‘/tmp/ForStandby_3tt1tql3_1_1‘;
2.3由于主备数据文件不一致,提取准备恢复脚本,
set newname数据文件目录转换信息 --使用sql连接符,拼接想要的SQL语句
[email protected] >select ‘set newname for datafile ‘||file#||‘ to ‘‘‘||name||‘‘‘;‘ from v$datafile;
------------------------------------------------------------------------------------------------------------------------
set newname for datafile 1 to ‘/picclife/app/oracle/oradata/dage/system01.dbf‘;
set newname for datafile 2 to ‘/picclife/app/oracle/oradata/dage/sysaux01.dbf‘;
set newname for datafile 3 to ‘/picclife/app/oracle/oradata/dage/undotbs01.dbf‘;
set newname for datafile 4 to ‘/picclife/app/oracle/oradata/dage/users01.dbf‘;
set newname for datafile 5 to ‘/picclife/app/oracle/oradata/dage/example01.dbf‘;
set newname for datafile 6 to ‘/picclife/app/oracle/oradata/dage/ceshi.dbf‘;
set newname for datafile 7 to ‘/picclife/app/oracle/oradata/dage/ces01.dbf‘;
set newname for datafile 8 to ‘/picclife/app/oracle/oradata/dage/ua01.dbf‘;
2.4备库不存在的数据文件,
进行restore还原
RMAN> run{
set newname for datafile 6 to ‘/picclife/app/oracle/oradata/dage/ceshi.dbf‘;
set newname for datafile 7 to ‘/picclife/app/oracle/oradata/dage/ces01.dbf‘;
set newname for datafile 8 to ‘/picclife/app/oracle/oradata/dage/ua01.dbf‘;
restore datafile 6,7,8;
}
#如果主备数据文件数量一致,此步骤可跳过
2.5进行数据恢复操作:
RMAN> recover database noredo;
--如果报错可使用
run{2.3查询的sernew输出内容+recover database redo}
3.0备库应用增量备份恢复后,验证备库的连通性 -
-启动MRP进程
[email protected] >ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
#--可选择的命令:对备库的日志组进行清空重置
#SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1;
#SQL> ALTER DATABASE CLEAR LOGFILE GROUP 2;
#SQL> ALTER DATABASE CLEAR LOGFILE GROUP 3;
#--On the STANDBY database, start the MRP
#SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
---本次操作遇到的问题:主库存在新的数据文件,且路径在备库并未转换
查询备库 06:39:09 [email protected] >select name from v$datafile;
NAME ------------------------------------------------------------------------------------------------------------------------
/picclife/app/oracle/oradata/dage/system01.dbf
/picclife/app/oracle/oradata/dage/sysaux01.dbf
/picclife/app/oracle/oradata/dage/undotbs01.dbf
/picclife/app/oracle/oradata/dage/users01.dbf
/picclife/app/oracle/oradata/dage/example01.dbf
/home/oracle/ceshi.dbf 000发现不一致的信息,需要处理
/home/oracle/ces01.dbf
/picclife/app/oracle/oradata/dage/ua01.dbf
8 rows selected.
--修改参数,数据文件转换参数,重启备库
06:40:08 [email protected] >alter system set db_file_name_convert=‘/u01/app/oracle/oradata/ENMO/‘,‘/picclife/app/oracle/oradata/dage/‘,‘/home/oracle/‘,‘/picclife/app/oracle/oradata/dage/‘ scope=spfile; 06:40:57 [email protected] >startup force mount; 06:41:10 [email protected] >select name from v$datafile;
NAME ------------------------------------------------------------------------------------------------------------------------
/picclife/app/oracle/oradata/dage/system01.dbf
/picclife/app/oracle/oradata/dage/sysaux01.dbf
/picclife/app/oracle/oradata/dage/undotbs01.dbf
/picclife/app/oracle/oradata/dage/users01.dbf
/picclife/app/oracle/oradata/dage/example01.dbf
/picclife/app/oracle/oradata/dage/ceshi.dbf
/picclife/app/oracle/oradata/dage/ces01.dbf
/picclife/app/oracle/oradata/dage/ua01.dbf
8 rows selected.
原文地址:https://www.cnblogs.com/lvcha001/p/9359758.html