问题现象:
-
SQL> alter database open resetlogs;
-
alter database open resetlogs
-
*
-
ERROR at line 1:
-
ORA-01152: file 1 was not restored from a sufficiently old backup
-
ORA-01110: data file 1: '/DBSoft/oracle/oradata/woo/system01.dbf'
日志中报错:
-
alter database open
-
Errors in file /DBSoft/oracle/diag/rdbms/woo/woo/trace/woo_ora_24956.trc:
-
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
-
ORA-1589 signalled during: alter database open...
-
Sun Dec 24 05:44:45 2017
-
Signalling error 1152 for datafile
-
Signalling error 1152 for datafile
-
Signalling error 1152 for datafile
-
Signalling error 1152 for datafile
-
Signalling error 1152 for datafile
-
Checker run found 5 new persistent data failures
-
Sun Dec 24 05:44:51 2017
-
alter database open resetlogs
-
Signalling error 1152 for datafile
-
ORA-1152 signalled during: alter database open resetlogs...
问题分析:
做完recover database正要起库,发现data file 1需要恢复,那么这个时候就应该要想到需要做不完全恢复了。那么不完全恢复自然有四种,基于时间(time)恢复
基于取消(cancel)恢复
基于SCN(change)恢复
基于备份控制文件(unsing backup controlfile)的恢复,那么接下来我们需要了解下,用那种方式最合适了。
查看scn信息:
查看数据文件头部的scn信息:
-
SQL> select checkpoint_change# from v$datafile_header;
-
-
CHECKPOINT_CHANGE#
-
------------------
-
2247792
-
2247792
-
2247792
-
2247792
-
2247792
查看控制文件中记录的scn头部信息:
-
SQL> select checkpoint_change# from v$datafile;
-
-
CHECKPOINT_CHANGE#
-
------------------
-
2247974
-
2247974
-
2247974
-
2247974
-
2247974
在这里我们可以很清楚的看到控制文件中记录的scn信息比数据文件头部记录的scn信息更新,且所有数据文件头部信息是一致的,由此可以快速得出,我们将数据库恢复到数据文件的scn这样数据库就可以打开了。
做基于文件头部的scn恢复:
-
SQL> recover database until change 2247792;
-
ORA-00283: recovery session canceled due to errors
-
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done
提示需要使用控制文件来做基于scn的恢复。
使用控制文件来做基于scn的恢复:
-
SQL> recover database until change 2247792 using backup controlfile;
-
Media recovery complete.
SQL> select * from v$recover_file
FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
---------- ------- ------- ---------- ---------- ------------------
1 ONLINE ONLINE 2247792 23-DEC-17
2 ONLINE ONLINE 2247792 23-DEC-17
3 ONLINE ONLINE 2247792 23-DEC-17
4 ONLINE ONLINE 2247792 23-DEC-17
5 ONLINE ONLINE 2247792 23-DEC-17
恢复完成之后,执行open resetlogs:
-
SQL> alter database open resetlogs;
-
-
Database altered.
检查:
-
SQL> col error format a10;
-
SQL> select * from v$recover_file;
-
-
no rows selected
-
-
SQL> select checkpoint_change# from v$datafile_header;
-
-
CHECKPOINT_CHANGE#
-
------------------
-
2247797
-
2247797
-
2247797
-
2247797
-
2247797
-
-
SQL> select checkpoint_change# from v$datafile;
-
-
CHECKPOINT_CHANGE#
-
------------------
-
2247797
-
2247797
-
2247797
-
2247797
-
2247797
总结:必须保证数据文件头部的scn和控制文件中的scn信息保持一致,数据库才能打开,那么正常恢复将遵循就近,就小来恢复。