数据库在执行全库恢复后,open时报错ORA-01113、ORA-01110 ORA-00312 ORA-01113

时间:2023-01-08 16:58:54
问题描述:数据库在执行全库恢复后,open时报错ORA-01113、ORA-01110 ORA-00312 ORA-01113
系统:Anolis 7.9
数据库:oracle 11.2.0.4
1、问题描述
数据库在执行全库恢复后,open时报错ORA-01113、ORA-01110,如下所示:
全库恢复:
RMAN> shutdown abort
RMAN> startup mount;
RMAN> run{
restore database;
recover database;
alter database open;
}
报错信息:
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf'
rman执行恢复报错ORA-00312

RMAN> recover datafile '/u01/app/oracle/oradata/orcl/system01.dbf';

Starting recover at 06-SEP-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=241 device type=DISK

starting media recovery
media recovery failed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 09/06/2022 21:42:14
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover if needed
datafile 1
ORA-00283: recovery session canceled due to errors
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/orcl/redo02.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

异常原因:联机日志出现异常.
说明:联机日志分为当前联机日志和非当前联机日志.非当前联机日志的损坏比较简单,通过clear命令就能解决.
2、非当前日志
非当前联机日志异常处理如下:
2.1、问题重现
启动数据库,报ORA-00312 or ORA-00313
ORA-00313: open failed for members of log group 4 of thread 1
ORA-00312: online log 3 thread 1: '/opt/oracle/db04/oradata/ORCL/redo03.log'
日志组3异常.
2.2、查v$log
SQL> select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARC STATUS
---------- ---------- --- ----------------
1 54 YES INACTIVE
2 55 NO CURRENT
3 53 YES INACTIVE
日志组3为非当前状态,且已归档.
2.3、重建日志文件
用CLEAR命令重建该日志文件.
SQL>alter database clear logfile group 3
若未归档,则
SQL>alter database clear unarchived logfile group 3;
2.4、open数据库
SQL>alter database open;
说明:open数据库后建议作一次全备份.
3、当前日志
损坏当前联机日志.
归档模式下当前日志的损坏有两种情况
a、数据库正常关闭,日志文件中没有活动事务需要实例恢复,当前日志组的损坏就可直接用alter database clear unarchived logfile group n重建.
b、日志文件中有活动事务,数据库需要media恢复,此时有两种补救办法.
b1、最好通过不完全恢复,可保证数据库一致性,但该方案要求归档方式,且有可用备份
b2、强制性恢复,可能导致数据库不一致下面分别说明两种恢复方法
3.1、备份恢复
3.1.1、异常重现
打开数据库,遇到类似错误.
3.1.2、查v$log
查看V$log,发现是当前日志.
SQL> select group#,sequence#,archived,status from v$log;

GROUP# SEQUENCE# ARC STATUS
---------- ---------- --- ----------------
1 0 YES UNUSED
3 0 YES UNUSED
2 2 NO CURRENT
3.1.3、clear fail
发现clear不成功
SQL> alter database clear unarchived logfile group 2;
alter database clear unarchived logfile group 2*ERROR at line 1:
ORA-01624: log 2 needed for crash recovery of thread 1
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/orcl/redo02.log'
3.1.4、恢复数据库
拷贝有效数据库的全备份,做不完全恢复数据库可以采用获取最近的SCN,用until scn或until cancel恢复.
recover database until cancel先选择auto
尽量恢复可以利用的归档日志,然后再recover database until cancel输入cancel
完成不完全恢复,也就是说恢复两次.
操作如下:
SQL> recover database until cancel;
Auto……
SQL> recover database until cancel;
Cancel;
3.1.5、open数据库
利用alter database open resetlogs打开数据库说明:
a、此为一致不完全恢复,会丢失当前联机日志中的事务数据
b、适合于归档数据库且有可用的数据库全备份.
c、恢复成功之后,记得再做一次数据库的全备份.
d、建议联机日志文件一定要镜相在不同的磁盘上,避免这种情况的发生,任何数据的丢失对于生产来说都是不容许的.
4、强制恢复
如果没有备份,进行强制性恢复
4.1、异常重现
打开数据库,抛出类似异常
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/orcl/redo02.log'
ORA-27041: unable to open file
OSD-04002: unable to open fileO/S-Error: (OS 2) 系统找不到指定的文件
4.2、查v$log
查看v$log,发现是当前日志SQL> select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS
---------- ---------- -------- ----------------
1 1 NO CURRENT
2 2 YES INACTIVE
3 3 YES INACTIVE
4.3、clear fail
发现clear不成功
SQL> alter database clear unarchived logfile group 1;
alter database clear unarchived logfile group 1
*ERROR at line 1:ORA-01624: log 1 needed for crash recovery of thread 1
ORA-00312: online log 1 thread 1: 'D:ORACLEORADATATESTREDO01.LOG'
4.4、关闭数据库
把数据库down掉
SQL>shutdown immediate
4.5、修改pfile
在init.ora中加入如下参数
_allow_resetlogs_corruption=TRUE
4.6、重启数据库
重新启动数据库,利用until cancel恢复
SQL>recover database until cancel;
Cancel
如果出错,不再理会,发出
SQL>alter database open resetlogs;
4.7、后续操作
数据库被打开后,马上执行一个full export
shutdown数据库,去掉_all_resetlogs_corrupt参数
重建库
import并完成恢复
建议执行一下ANALYZE TABLE ...VALIDATE STRUCTURE CASCADE;
说明:
a、该恢复方法是最后的恢复方法,建议不要采用,该方法可能导致数据库不一致
b、该方法也丢失数据,但丢失的数据没有上一种的数据多,主要是未写入数据文件的已提交或未提交数据.
c、建议成功后严格执行3.7的步骤,完成数据库的检查与分析
d、建议联机日志文件要镜相在不同磁盘上,避免这种情况的发生,因为任何数据的丢失对于生产来说都是不容许的.

参考网址:
http://blog.itpub.net/166555/viewspace-783944/