欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

恢复控制文件后如何避免resetlogs打开数据库?

程序员文章站 2022-05-05 23:20:21
...

恢复控制文件后,数据库使用resetlogs方式打开,在线日志的序列被重置。

恢复控制文件后,数据库使用resetlogs方式打开,在线日志的序列被重置。

SYS@practice >select group#,sequence#,archived,status,first_change#,next_change# from v$log;

GROUP# SEQUENCE# ARC STATUS FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- --- ---------------- ------------- ------------
1 1 NO CURRENT 1014415 2.8147E+14
2 0 YES UNUSED 0 0
3 0 YES UNUSED 0 0

如果没有被resetlog截断的话当前日志的序列号应该是7,8,9
SYS@practice >select recid,sequence#,first_change#,next_change# from v$log_history;

RECID SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ------------- ------------
1 1 925702 955284
2 2 955284 955847
3 3 955847 971151
4 4 971151 987800
5 5 987800 997957
6 6 997957 1010981
7 1 1010981 1013463
8 2 1013463 1013471
9 3 1013471 1014415

如果恢复完控制文件,不使用resetlogs是打不开数据库的。

我们可以采取手工创建控制文件的方法打开数据库,保持联机日志的sequence#连续。下面的实验来演示具体操作过程。

在实验之前先手工切换3次日志,使得在线日志的序列号产生变化。在恢复结束后作为参考。
SYS@practice >alter system archive log current;

SYS@practice >alter system archive log current;

SYS@practice >alter system archive log current;

切换后当前连接日志状态如下
SYS@practice >select group#,sequence#,archived,status,first_change#,next_change# from v$log;

GROUP# SEQUENCE# ARC STATUS FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- --- ---------------- ------------- ------------
1 4 NO CURRENT 1030130 2.8147E+14
2 2 YES INACTIVE 1030109 1030117
3 3 YES ACTIVE 1030117 1030130

1,恢复控制文件
RMAN> startup force nomount;

Oracle instance started

Total System Global Area 580395008 bytes

Fixed Size 2255392 bytes
Variable Size 402654688 bytes
Database Buffers 171966464 bytes
Redo Buffers 3518464 bytes

RMAN> restore controlfile from autobackup;

Starting restore at 06-OCT-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

recovery area destination: /u01/fast_recovery_area
database name (or database unique name) used for search: PRACTICE
channel ORA_DISK_1: AUTOBACKUP /u01/fast_recovery_area/PRACTICE/autobackup/2014_10_06/o1_mf_s_860251717_b35s05gm_.bkp found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141006
channel ORA_DISK_1: restoring control file from AUTOBACKUP /u01/fast_recovery_area/PRACTICE/autobackup/2014_10_06/o1_mf_s_860251717_b35s05gm_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/u01/oradata/practice/control01.ctl
output file name=/u01/fast_recovery_area/practice/control02.ctl
Finished restore at 06-OCT-14

2,启动数据库到mount状态
RMAN> mount database;

database mounted
released channel: ORA_DISK_1

3,恢复数据库
RMAN> recover database;