共计 5664 个字符,预计需要花费 15 分钟才能阅读完成。
今天一个开发库启动不了了,发过来报错一看是日志文件损坏了 (见下图),接着说了一下前因后果。说是年前服务器掉电了,然后就再没有启动起来过。今天有人用才想到要处理。
先说一下大体的思路,如果损坏的 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 是实例崩溃恢复所需要的日志文件,不能直接重建。
4、这种情况下使用隐含参数_allow_resetlogs_corruption,创建 pfile,把 *._allow_resetlogs_corruption=TRUE 加入到 pfile 中。然后 mount 数据库,强制不完全恢复,再 open resetlogs
idle>create pfile=’/home/oracle/initorcl.ora’ from spfile;
File created.
[oracle@rhel6 orcl]$ vi /home/oracle/initorcl.ora
idle>shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
idle>startup pfile=’/home/oracle/initorcl.ora’ mount;
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.
idle>show parameter _allow_
NAME TYPE VALUE
———————————— ——————————— ——————————
_allow_resetlogs_corruption boolean TRUE
idle>recover database until cancel;
ORA-00279: change 1023441 generated at 02/24/2017 23:54:54 needed for thread 1
ORA-00289: suggestion : /u02/app/oracle/product/11.2.4/db1/dbs/arch1_2_936817668.dbf
ORA-00280: change 1023441 for thread 1 is in sequence #2
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: ‘/u02/app/oracle/oradata/orcl/system01.dbf’
ORA-01112: media recovery not started
idle>alter database open resetlogs;
Database altered.
idle>select open_mode from v$database;
OPEN_MODE
————————————————————
READ WRITE
可以看到现在数据库已经被 open 了。
5、再次查看第一步中被删除的数据的表,数据仍然存在说明丢失 CURRENT 或 ACTIVE 状态的日志文件会导致数据丢失。
idle>select count(*) from zx;
COUNT(*)
———-
2858
以上是在虚拟机上做测试的恢复过程,但是对于前面说到的开发库的恢复就没有这个过程简单了。可以说是解决了一个报错又出来新的报错。
在使用_allow_resetlogs_corruption 参数执行不完全恢复,open resetlogs 时,遇到了 ORA-01248
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01248: file 5 was created in the future of incomplete recovery
于是先把这个文件 offline drop
1 SQL> alter database datafile 5 offline drop;
再次 open resetlogs 时又遇到了 ORA-00704 和 ORA-01555
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-00704: bootstrap process failure
ORA-00704: bootstrap process failure
ORA-00604: error occurred at recursive SQL level 1
ORA-01555: snapshot too old: rollback segment number 5 with name
“_SYSSMU5_4116806824$” too small
Process ID: 3396
Session ID: 573 Serial number: 51
由于现在的水平有限,在网上查资料也没有能解决这一系列的问题,最后没办法只能重建库,重新导数据了。
如果哪位遇到了类似的问题,而且解决了,也请分享一下经验。
其实上午在模拟这个问题的时候,在 open resetlogs 时还遇到了一个经典的报错 ORA-600 [2662],这个错误可以参考 http://www.linuxidc.com/Linux/2017-02/141074.htm
参考:http://www.linuxidc.com/Linux/2017-02/141073.htm
http://www.linuxidc.com/Linux/2012-02/53426.htm
更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-02/141072.htm