今天一个开发库启动不了了,发过来报错一看是日志文件损坏了(见下图),接着说了一下前因后果。说是年前服务器掉电了,然后就再没有启动起来过。今天有人用才想到要处理。
先说一下大体的思路,如果损坏的redo log是INACTIVE状态的,也就是实例崩溃恢复用不到的redo log,那处理起来比较容易,直接alter database clear logfile group #;或alter database clear unarchived logfile group #;重建日志组就行了。建议重建日志文件级后对数据库做一个全库备份,特别是强制clear后,造成的归档日志文件断层。在如果损坏的redo log是ACTIVE或CURRENT状态的,也就是实例崩溃恢复需要用到的redo log,那处理起来就比较麻烦了,损坏这种redo log就意味着丢失数据。
redo log的三种状态:
INACTIVE:日志对应的修改已经被写入硬盘
ACTIVE:日志对应的修改还没有被写入硬盘
CURRENT:实例正在使用的日志文件
由于这个开发库有种种的问题,恢复起来遇到了各种情况,这里用一个虚拟机上的数据库演示如果CURRENT或ACTIVE状态的日志文件损坏的情况下如何恢复。
1、构造场景
删除一张表的数据但不提交,然后在另一个会话中把数据库shutdown abort。再删除所有的redo log文件。
#session 1
sys@ORCL>delete from zx;
2858 rows deleted.
#session 2
sys@ORCL>select group#,status from v$log;
GROUP# STATUS
---------- ------------------------------------------------
1 INACTIVE
2 ACTIVE
3 CURRENT
sys@ORCL>shutdown abort;
Oracle instance shut down.
#删除redo log文件
[oracle@rhel6 ~]$ cd /u02/app/oracle/oradata/orcl/
[oracle@rhel6 orcl]$ ls -l
total 1944992
-rw-r----- 1 oracle oinstall 9748480 Feb 24 23:56 control01.ctl
-rw-r----- 1 oracle oinstall 9748480 Feb 24 23:56 control02.ctl
-rw-r----- 1 oracle oinstall 328343552 Feb 24 23:54 example01.dbf
-rw-r----- 1 oracle oinstall 52429312 Feb 24 23:54 redo01.log
-rw-r----- 1 oracle oinstall 52429312 Feb 24 23:55 redo02.log
-rw-r----- 1 oracle oinstall 52429312 Feb 24 23:55 redo03.log
-rw-r----- 1 oracle oinstall 545267712 Feb 24 23:54 sysaux01.dbf
-rw-r----- 1 oracle oinstall 796925952 Feb 24 23:54 system01.dbf
-rw-r----- 1 oracle oinstall 30416896 Feb 24 13:58 temp01.dbf
-rw-r----- 1 oracle oinstall 110108672 Feb 24 23:54 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 Feb 24 23:54 users01.dbf
[oracle@rhel6 orcl]$ rm redo*log
l[oracle@rhel6 orcl]$ ls -l
total 1791212
-rw-r----- 1 oracle oinstall 9748480 Feb 24 23:56 control01.ctl
-rw-r----- 1 oracle oinstall 9748480 Feb 24 23:56 control02.ctl
-rw-r----- 1 oracle oinstall 328343552 Feb 24 23:54 example01.dbf
-rw-r----- 1 oracle oinstall 545267712 Feb 24 23:54 sysaux01.dbf
-rw-r----- 1 oracle oinstall 796925952 Feb 24 23:54 system01.dbf
-rw-r----- 1 oracle oinstall 30416896 Feb 24 13:58 temp01.dbf
-rw-r----- 1 oracle oinstall 110108672 Feb 24 23:54 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 Feb 24 23:54 users01.dbf
2、启动数据库出现报错
idle>startup
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 1476398240 bytes
Database Buffers 117440512 bytes
Redo Buffers 7319552 bytes
Database mounted.
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u02/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
3、尝试使用clear方式重建日志组出现报错
idle>alter database clear logfile group 2;
alter database clear logfile group 2
*
ERROR at line 1:
ORA-01624: log 2 needed for crash recovery of instance orcl (thread 1)
ORA-00312: online log 2 thread 1: '/u02/app/oracle/oradata/orcl/redo02.log'
idle>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 instance orcl (thread 1)
ORA-00312: online log 2 thread 1: '/u02/app/oracle/oradata/orcl/redo02.log'
从报错信息中可以看出log 2是实例崩溃恢复所需要的日志文件,不能直接重建。