制造gap
在主库上停止向备库传输日志
SQL> alter system set log_archive_dest_state_2=defer scope=memory;
System altered.
在主库进行几次日志切换,并将切换的日志删除,在错误备库的错误日志中可以看到:
Archived Log entry 20 added for thread 1 sequence 123 rlc 913820033 ID 0x55ec8100 dest 2:
Tue Jan 21 10:58:49 2020
Fetching gap sequence in thread 1, gap sequence 120-121
Tue Jan 21 11:00:40 2020
FAL[client]: Failed to request gap sequence
GAP - thread 1 sequence 120-121
DBID 1441600768 branch 913820033
FAL[client]: All defined FAL servers have been attempted.
------------------------------------------------------------
Check that the CONTROL_FILE_RECORD_KEEP_TIME initialization
parameter is defined to a value that's sufficiently large
enough to maintain adequate log switch information to resolve
archivelog gaps.
------------------------------------------------------------
Tue Jan 21 11:05:48 2020
Archived Log entry 21 added for thread 1 sequence 124 rlc 913820033 ID 0x55ec8100 dest 2:
RFS[5]: No standby redo logfiles created for thread 1
在备库中检查视图发现:
select * from v$archive_gap;
THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
---------- ------------- --------------
1 120 121
从主库进行增量SCN的备份
如果能找到日志文件,将其传输过去,注册即可。
SQL> alter database register logfile ‘<File-Specification>’;
如果找不到日志文件,可以按备库当前的SCN号从主库生成一个增量备份恢复到主库 参见文档:https://docs.oracle.com/cd/B19306_01/server.102/b14239/scenarios.htm#CIHIAADC
停止备库的日志应用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Database altered.
SQL> select * from v$archive_gap;
THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
---------- ------------- --------------
1 120 121
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY
找出备库当前的SCN号:
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
3085099
查看datafile中有无没有记录log的scn
SQL> SELECT MIN(FIRST_NONLOGGED_SCN) FROM V$DATAFILE WHERE FIRST_NONLOGGED_SCN>0;
MIN(FIRST_NONLOGGED_SCN)
------------------------
SQL>
运气不错,没有,好了,现在确定最小的SCN是3085099,从主库以这个SCN开始进行增量备份。
RMAN> BACKUP INCREMENTAL FROM SCN 3085099 DATABASE FORMAT '/tmp/ForStandby_%U' tag 'FORSTANDBY';
Starting backup at 21-JAN-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=46 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=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 21-JAN-20
channel ORA_DISK_1: finished piece 1 at 21-JAN-20
piece handle=/tmp/ForStandby_0iumhqn9_1_1 tag=FORSTANDBY comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
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 21-JAN-20
channel ORA_DISK_1: finished piece 1 at 21-JAN-20
piece handle=/tmp/ForStandby_0jumhqo2_1_1 tag=FORSTANDBY comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 21-JAN-20
[oracle@rhel65 orcl]$ ls -l /tmp/ForStandby_*
-rw-r----- 1 oracle oinstall 14376960 1月 21 14:34 /tmp/ForStandby_0iumhqn9_1_1
-rw-r----- 1 oracle oinstall 10027008 1月 21 14:34 /tmp/ForStandby_0jumhqo2_1_1
把备份的文件传输到备库的机器上
在备库上恢复
将传输的文件在备库上注册。
RMAN> catalog start with '/tmp/ForStandby';
searching for all files that match the pattern /tmp/ForStandby
List of Files Unknown to the Database
=====================================
File Name: /tmp/ForStandby_0jumhqo2_1_1
File Name: /tmp/ForStandby_0iumhqn9_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: /tmp/ForStandby_0jumhqo2_1_1
File Name: /tmp/ForStandby_0iumhqn9_1_1
使用report schema检查备库是rman target,并检查文件名。
list backup
.....
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8 Incr 9.55M DISK 00:00:00 21-JAN-20
BP Key: 8 Status: AVAILABLE Compressed: NO Tag: FORSTANDBY
Piece Name: /tmp/ForStandby_0jumhqo2_1_1
Control File Included: Ckp SCN: 3104501 Ckp time: 21-JAN-20
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9 Incr 13.70M DISK 00:00:00 21-JAN-20
BP Key: 9 Status: AVAILABLE Compressed: NO Tag: FORSTANDBY
Piece Name: /tmp/ForStandby_0iumhqn9_1_1
List of Datafiles in backup set 9
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Incr 3104431 21-JAN-20 /u01/app/oracle/oradata/orcl/system01.dbf
2 Incr 3104431 21-JAN-20 /u01/app/oracle/oradata/orcl/sysaux01.dbf
3 Incr 3104431 21-JAN-20 /u01/app/oracle/oradata/orcl/undotbs01.dbf
4 Incr 3104431 21-JAN-20 /u01/app/oracle/oradata/orcl/users01.dbf
5 Incr 3104431 21-JAN-20 /u01/app/oracle/oradata/orcl/example01.dbf
这里注意检查control file的文件名是’/tmp/ForStandby_0jumhqo2_1_1’,下面恢复的时候要用这个文件名。
SQL> startup force nomount;
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2253824 bytes
Variable Size 331353088 bytes
Database Buffers 79691776 bytes
Redo Buffers 4247552 bytes
RMAN> restore standby controlfile from '/tmp/ForStandby_0jumhqo2_1_1';
Starting restore at 21-JAN-20
using channel ORA_DISK_1
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orcl/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/orcl/control02.ctl
Finished restore at 21-JAN-20
RMAN> ALTER DATABASE MOUNT;
database mounted
released channel: ORA_DISK_1
RMAN> RECOVER DATABASE NOREDO;
Starting recover at 21-JAN-20
Starting implicit crosscheck backup at 21-JAN-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 21-JAN-20
Starting implicit crosscheck copy at 21-JAN-20
using channel ORA_DISK_1
Crosschecked 4 objects
Finished implicit crosscheck copy at 21-JAN-20
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
Finished recover at 21-JAN-20
RMAN>
noredo的意思上后续不要apply archivelog。
注意recover时要小心主库和备库的文件名不一样的情况,要用 SET NEWNAME指定不同的路径再recover database,可以先用report schema查询。
SET NEWNAME FOR DATAFILE 1 TO '/oradata1/system01.dbf';
SET NEWNAME FOR DATAFILE 2 TO '/oradata2/undotbs01.dbf';
SET NEWNAME FOR DATAFILE 3 TO '/oradata3/cwmlite01.dbf';
SET NEWNAME FOR DATAFILE 4 TO '/oradata4/drsys01';
SET NEWNAME FOR DATAFILE 5 TO '/oradata5/example01.dbf';
SET NEWNAME FOR TEMPFILE 1 TO '/disk2/temp01.dbf';
后续检查
SQL> select * from v$archive_gap;
no rows selected
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
来源:CSDN
作者:遥远2018
链接:https://blog.csdn.net/weixin_43424368/article/details/104059977