您的位置:首页 > 数据库 > Oracle

oracle 联机日志文件损坏的几种场景和恢复方法

2014-04-25 16:39 573 查看
oracle联机日志文件记录数据库运行过程中数据块改变的日志,在数据库出现介质损坏或者异常挂掉后,需要通过联机日志(或归档)日志,重演数据库发生的改变。因此,我们知道,联机日志对于Oracle数据库的重要性不言而喻!
但是,再稳定,再强壮的系统,都有可能出现意外情况,导致联机日志文件损坏,在日志文件本身出现损坏(丢失)的情况下,数据库可能出现无法正常打开,这一篇文章就是针对这种情况下进行的简单恢复测试,实际恢复情况肯定更加复杂!(仅供参考)
一、联机日志文件损坏分类
1、inactive 状态(不会造成数据丢失)
2、active、current状态(一般会造成数据丢失)
查看方法:
SQL> select group#,thread#,archived,status from v$log;

    GROUP#    THREAD# ARC STATUS
---------- ---------- --- ----------------
         1          1 YES INACTIVE
         2          1 NO  CURRENT
         3          1 YES INACTIVE

二、测试环境

OS: Linux xxxxxxxx  2.6.18-238.el5 #1 SMP Thu Jan 13 15:51:15 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
DB: oracle 11.2.0.1.6(非RAC)

三、inactive 状态联机日志文件损坏的恢复测试
startup时错误日志:
SQL> startup
ORACLE instance started.

Total System Global Area 3156877312 bytes
Fixed Size                  2217424 bytes
Variable Size             989858352 bytes
Database Buffers         2147483648 bytes
Redo Buffers               17317888 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 29499
Session ID: 2273 Serial number: 5

alert错误日志:
Errors in file /u01/oracle/diag/rdbms/test/test/trace/test_lgwr_29457.trc:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/test/test/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Errors in file /u01/oracle/diag/rdbms/test/test/trace/test_lgwr_29457.trc:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/test/test/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Errors in file /u01/oracle/diag/rdbms/test/test/trace/test_ora_29499.trc:
ORA-00313: open failed for members of log group 1 of thread 
ORA-00312: online log 1 thread 1: '/u01/test/test/redo01.log'
USER (ospid: 29499): terminating the instance due to error 313
Instance terminated by USER, pid = 29499

这种情况下,只需将active的日志组删除,然后startup,如下:
SQL> startup mount;
ORACLE instance started.
Total System Global Area 3156877312 bytes
Fixed Size                  2217424 bytes
Variable Size             989858352 bytes
Database Buffers         2147483648 bytes
Redo Buffers               17317888 bytes
Database mounted.
SQL> alter database drop logfile group 1;  
Database altered.
SQL> alter database open;
Database altered.

备注,如果该联机日志还未完成归档,需使用如下命令删除
 alter database clear unarchived logfile group 3;

四、active、current状态的联机日志文件损坏
startup时错误:
SQL> startup
ORACLE instance started.
Total System Global Area 3156877312 bytes
Fixed Size                  2217424 bytes
Variable Size             989858352 bytes
Database Buffers         2147483648 bytes
Redo Buffers               17317888 bytes
Database mounted.
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/test/test/redo03.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> select group#,thread#,archived,status from v$log;
    GROUP#    THREAD# ARC STATUS
---------- ---------- --- ----------------
         1          1 NO  CURRENT
         3          1 YES ACTIVE
         2          1 YES INACTIVE

alert日志错误:
Completed: ALTER DATABASE   MOUNT
Fri Apr 25 16:49:21 2014
ALTER DATABASE OPEN
Beginning crash recovery of 1 threads
 parallel recovery started with 2 processes
Started redo scan
Errors in file /u01/oracle/diag/rdbms/test/test/trace/test_ora_29862.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/test/test/redo03.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Aborting crash recovery due to error 313
Errors in file /u01/oracle/diag/rdbms/test/test/trace/test_ora_29862.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/test/test/redo03.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Errors in file /u01/oracle/diag/rdbms/test/test/trace/test_ora_29862.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/test/test/redo03.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
ORA-313 signalled during: ALTER DATABASE OPEN...
Fri Apr 25 16:49:21 2014
Errors in file /u01/oracle/diag/rdbms/test/test/trace/test_m000_29874.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/test/test/redo03.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Checker run found 2 new persistent data failures

这种情况下无法删除active联机日志,尝试各种删除方式都会报错,如下:
SQL> alter database drop logfile group 3;
alter database drop logfile group 3
*
ERROR at line 1:
ORA-01624: log 3 needed for crash recovery of instance test (thread 1)
ORA-00312: online log 3 thread 1: '/u01/test/test/redo03.log'
SQL> alter database clear logfile group 3;
alter database clear logfile group 3
*
ERROR at line 1:
ORA-01624: log 3 needed for crash recovery of instance test (thread 1)
ORA-00312: online log 3 thread 1: '/u01/test/test/redo03.log'
SQL> alter database clear unarchived logfile group 3;
alter database clear unarchived logfile group 3
*
ERROR at line 1:
ORA-01624: log 3 needed for crash recovery of instance test (thread 1)
ORA-00312: online log 3 thread 1: '/u01/test/test/redo03.log'

尝试使用不完全恢复(recover database  until cancel) 和 open resetlogs方式打开数据库也会失败,如下:
SQL> recover database until cancel;
ORA-00279: change 1015952 generated at 04/25/2014 16:47:37 needed for thread 1
ORA-00289: suggestion : /u01/archtestarch_1_12_845826452.arc
ORA-00280: change 1015952 for thread 1 is in sequence #12
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
ORA-10879: error signaled in parallel recovery slave
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: '/u01/test/test/system01.dbf

SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/test/test/system01.dbf'

这种情况下,需要设置隐含参数“_allow_resetlogs_corruption”强制打开数据库(数据库会处于不一致状态),如下:

a.确定所有数据文件都不处于备份状态:

SQL> select 'alter database datafile '''||name||''' end backup;' from v$datafile;

'ALTERDATABASEDATAFILE'''||NAME||'''ENDBACKUP;'
--------------------------------------------------------------------------------
alter database datafile '/u01/test/test/system01.dbf' end backup;
alter database datafile '/u01/test/test/sysaux01.dbf' end backup;
alter database datafile '/u01/test/test/undotbs01.dbf' end backup;
alter database datafile '/u01/test/test/users01.dbf' end backup;

SQL> alter database datafile '/u01/test/test/system01.dbf' end backup;
alter database datafile '/u01/test/test/system01.dbf' end backup

ERROR at line 1:
ORA-01235: END BACKUP failed for 1 file(s) and succeeded for 0
ORA-01199: file 1 is not in online backup mode                  --说明数据文件目前不处于备份模式,可以忽略
ORA-01110: data file 1: '/u01/test/test/system01.dbf'
............
...........
b.设置隐含参数,并重新启动到mount状态
SQL> alter system set "_allow_resetlogs_corruption"=TRUE scope=spfile;
System altered.
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 3156877312 bytes
Fixed Size                  2217424 bytes
Variable Size             989858352 bytes
Database Buffers         2147483648 bytes
Redo Buffers               17317888 bytes
Database mounted.

c.使用open resetlogs方式强制打开数据库
SQL> alter database open;    --------正常的open方式无法打开数据库
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;
Database altered.

d.其它注意事项

1.如果open resetlogs打开时提示需要进行恢复,可以使用recover database until cancel,然后输入所有可用的归档日志和联机日志,然后输入cancel取消恢复操作,再重新使用alter database open resetlogs方式打开数据库。

2.将隐含参数去掉,重新打开数据库

3.由于数据库中数据处于一种不一致状态,因此数据库打开后,需要立即进行全库导出和恢复

4.建议使用 ANALYZE
TABLE…VALIDATE STRUCTURE CASCADE 命令检查数据一致性(其它可以检查数据一致性的工具也可以)

5.由于是强制方式(不一致方式)打开数据库,因此数据库发生故障前,未提交的数据可能被标记为提交状态

6.强制打开数据库的过程中可能会遭遇其它ORA-600错误,如果第一个参数未400N,可能与回滚段有关,可再MOS查找解决方法,一一解决启动过程中遇到600错误,最后打开数据库,或者是2662,与SCN有关。

7.如果时间允许,最好保留现场(将数据文件进行一次备份)

回滚问题一般处理方法:

1.将回滚段管理方式改为手工,然后尝试启动数据库,如果不成功则尝试下一步
2.尝试设置一些event(10513
等)尝试启动数据库,未成功则下一步
3.使用_offline_rollback_segments/_corrupted_rollback_segments屏蔽回滚段
4.如果依然不能open数据库,考虑使用bbed工具提交事务,修改回滚段状态等操作
5.如果依然还不能open数据库,考虑使用dul

备注

rac中一个节点(至少一个节点存活)的日志文件(active、current)丢失,处理方式如下:

1.关闭所有实例

2.在受损实例上,启动到mount状态

3.执行alter database open resetlogs命令

4.如果需要,先用recover database until cancel 命令模拟一次不完全恢复

5.实例启动成功后,启动其他实例

6.立即对数据库进行一次全备份
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息