[小e笔记]之一步一步学习备份恢复——第三篇 数据库恢复案例(Part 8)

 

小e随笔:最近这一个礼拜,大四的课程快结束了,课程排的满,期末考试复习,进入11月中旬就进入自由实习期了,可是小e我的实习工作还没有找好,弄的我焦头烂额的,希望哪个伯乐赶紧收下我吧!!!我喜欢数据库。。。

案例4:丢失联机重做日志文件的恢复

1  丢失非当前的联机重做日志文件

(1)   重做日志文件定位

SQL> select group#,sequence#,members,archived,status from v$log;

    GROUP#  SEQUENCE#    MEMBERS ARC STATUS

---------- ---------- ---------- --- ----------------

         1          7          1 YES INACTIVE

         2          8          1 YES INACTIVE

         3          9          1 NO  CURRENT      --这个是当前重做日志文件

这个视图中status列的知识充电:

a.     UNUSED:表示从未用过。一般刚刚创建或OPEN RESETLOGS打开后,联机重做日志组为这一状态。

b.     CURRENT:表示当前的。

c.     ACTIVE:表示活动的。虽然不是当前状态,但也有可能正被使用或要被使用,比如CRASH RECOVERY时可能存在这种状态的联机重做组。

d.     CLEARING:日志正在清空,当执行ALTER DATABASE CLEAR LOGFILE语句时该日志组会变为这种状态,语句执行完后,操作的日志组状态变为UNUSED。

e.     CLEARING_CURRENT:日志正在清空。但是由于清空时出错如I/O设备无法访问,导致清空工作不能顺序完成,则该日志组就被置于这种状态。

f.      INACTIVE:不活动状态。表示该组日志中的内容已经被归档或顺利写入数据文件,该组日志可被继续重用。

SQL> col member format a50;

SQL> select group#,member from v$logfile;

    GROUP# MEMBER

---------- --------------------------------------------------

         1 /u01/oracle/oradata/elvis/redo01.log

         3 /u01/oracle/oradata/elvis/redo03.log

         2 /u01/oracle/oradata/elvis/redo02.log

经过这两个视图的定位,我们打算模拟损坏的日志就已经被我们选出来啦!那就是。。。2号文件,还有经过v$logfile视图你可以看到,我没一组重做日志文件里只有一个文件,这是相当不安全的。建议对联机重做日志文件进行冗余的机制来确保联机重做日志文件的安全,即每组联机重做日志创建多个文件(至少两个),每个文件的路径都可以各自独立(Oracle建议将每一组中的各个文件存放在不同的磁盘上)。

(2)   模拟文件丢失

[oracle@elvis elvis]$ ll

total 2080944

drwxr-xr-x 2 oracle oinstall      4096 Oct 13 19:49 bak

-rw-r----- 1 oracle oinstall  10076160 Oct 20 11:32 control01.ctl

-rw-r----- 1 oracle oinstall  52429312 Oct 20 10:12 redo01.log

-rw-r----- 1 oracle oinstall 52429312 Oct 20 10:12 redo02.log

-rw-r----- 1 oracle oinstall  52429312 Oct 20 11:30 redo03.log

-rw-r----- 1 oracle oinstall 629153792 Oct 20 11:27 sysaux01.dbf

-rw-r----- 1 oracle oinstall 734011392 Oct 20 11:28 system01.dbf

-rw-r----- 1 oracle oinstall  71311360 Oct 20 11:12 temp01.dbf

-rw-r----- 1 oracle oinstall  52436992 Oct 20 10:12 test01.dbf

-rw-r----- 1 oracle oinstall 524296192 Oct 20 11:27 undotbs02.dbf

-rw-r----- 1 oracle oinstall   5251072 Oct 20 10:12 users01.dbf

[oracle@elvis elvis]$ pwd

/u01/oracle/oradata/elvis

[oracle@elvis elvis]$ mv redo02.log redo02.log.bak

温馨提示:操作系统Win下不可以在线删除,而Linux下可以在线删除

SQL> startup

ORACLE instance started.

Total System Global Area  598437888 bytes

Fixed Size                  1338140 bytes

Variable Size             398460132 bytes

Database Buffers          192937984 bytes

Redo Buffers                5701632 bytes

Database mounted.

ORA-03113: end-of-file on communication channel

Process ID: 9950

Session ID: 1 Serial number: 5

错误比较奇怪。。。先看下告警日志的提示

查看了下告警日志文件:

ALTER DATABASE OPEN

Beginning crash recovery of 1 threads

Started redo scan

Completed redo scan

 read 3 KB redo, 9 data blocks need recovery

Started redo application at

 Thread 1: logseq 9, block 54675

Recovery of Online Redo Log: Thread 1 Group 3 Seq 9 Reading mem 0

  Mem# 0: /u01/oracle/oradata/elvis/redo03.log

Completed redo application of 0.00MB

Completed crash recovery at

 Thread 1: logseq 9, block 54682, scn 967166

 9 data blocks read, 9 data blocks written, 3 redo k-bytes read

LGWR: STARTING ARCH PROCESSES

Sat Oct 20 11:35:38 2012

ARC0 started with pid=20, OS id=9383

ARC0: Archival started

LGWR: STARTING ARCH PROCESSES COMPLETE

ARC0: STARTING ARCH PROCESSES

Sat Oct 20 11:35:39 2012

ARC1 started with pid=21, OS id=9387

Sat Oct 20 11:35:40 2012

ARC2 started with pid=22, OS id=9391

Errors in file /u01/oracle/diag/rdbms/elvis/elvis/trace/elvis_lgwr_9292.trc:

ORA-00313: open failed for members of log group 2 of thread 1

ORA-00312: online log 2 thread 1: '/u01/oracle/oradata/elvis/redo02.log'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

Errors in file /u01/oracle/diag/rdbms/elvis/elvis/trace/elvis_lgwr_9292.trc:

ORA-00313: open failed for members of log group 2 of thread 1

ORA-00312: online log 2 thread 1: '/u01/oracle/oradata/elvis/redo02.log'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

Errors in file /u01/oracle/diag/rdbms/elvis/elvis/trace/elvis_ora_9379.trc:

ORA-00313: open failed for members of log group 1 of thread

ORA-00312: online log 2 thread 1: '/u01/oracle/oradata/elvis/redo02.log'

USER (ospid: 9379): terminating the instance due to error 313

Sat Oct 20 11:35:40 2012

ARC3 started with pid=23, OS id=9395

Instance terminated by USER, pid = 9379

可以看出丢失日志组2文件的错误提示,与我们想要的结果一致,但是小e10g实验的时候应该在开启时直接报了这个丢失文件的错误,但现在在11g却不是这样,这个地方也疑惑了下,看恢复。。。

(3)恢复重做日志文件

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@elvis ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sat Oct 20 13:37:54 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup mount

ORACLE instance started.

Total System Global Area  598437888 bytes

Fixed Size                  1338140 bytes

Variable Size             398460132 bytes

Database Buffers          192937984 bytes

Redo Buffers                5701632 bytes

Database mounted.

SQL> alter database clear logfile group 2;

 

Database altered.

SQL> select group#,sequence#,members,archived,status from v$log;

 

    GROUP#  SEQUENCE#    MEMBERS ARC STATUS

---------- ---------- ---------- --- ----------------

         1          7          1 YES INACTIVE

         3          9          1 NO  CURRENT

         2          0          1 YES UNUSED

SQL> alter database open;

Database altered.

数据库正常开启了。

总结:恢复方法和传统恢复方法一样,但错误的提示方式,却与我在10g上的不同,我记得10g应该是提示
ORA-00313: open failed for members of log group 1 of thread 

ORA-00312: online log 2 thread 1: '/u01/oracle/oradata/elvis/redo02.log'
而这次实验的环境11g,却提示的这个错误,总之恢复了能开启就行啦,哈哈,如果哪位高手对刚刚那个地方有什么更好的见解,给小e留言哈,咱们互相讨论学习。

 

温馨提示:在数据库运行过程中,非当前的联机重做日志文件损坏不一定会导致数据库崩溃,因为非当前日志暂时并未用到,数据库还能正常运行,不过一旦数据库切换到损坏的联机重做日志文件时,就会发现该文件无法访问而导致报错。

 

2 丢失当前的联机重做日志文件

如果丢失当前联机重做日志文件,数据肯定会有丢失 ,除非除非你运气好到了极点。。。

怎么判断哪个是当前日志文件了,前面模拟过了。

(1)模拟文件损坏

[oracle@elvis elvis]$ ll

total 2081104

drwxr-xr-x 2 oracle oinstall      4096 Oct 13 19:49 bak

-rw-r----- 1 oracle oinstall  10076160 Oct 20 14:53 control01.ctl

-rw-r----- 1 oracle oinstall  52429312 Oct 20 13:57 redo01.log

-rw-r----- 1 oracle oinstall  52429312 Oct 20 14:50 redo02.log

-rw-r----- 1 oracle oinstall  52429312 Oct 20 13:57 redo03.log

-rw-r----- 1 oracle oinstall 629153792 Oct 20 14:43 sysaux01.dbf

-rw-r----- 1 oracle oinstall 734011392 Oct 20 14:44 system01.dbf

-rw-r----- 1 oracle oinstall  71311360 Oct 20 14:20 temp01.dbf

-rw-r----- 1 oracle oinstall  52436992 Oct 20 13:57 test01.dbf

-rw-r----- 1 oracle oinstall 524296192 Oct 20 14:44 undotbs02.dbf

-rw-r----- 1 oracle oinstall   5251072 Oct 20 13:57 users01.dbf

[oracle@elvis elvis]$ mv redo02.log redo02.log.bak

(2)模拟宕机&尝试开启数据库

SQL> shutdown abort;

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area  598437888 bytes

Fixed Size                  1338140 bytes

Variable Size             398460132 bytes

Database Buffers          192937984 bytes

Redo Buffers                5701632 bytes

Database mounted.

ORA-00313: open failed for members of log group 2 of thread 1

ORA-00312: online log 2 thread 1: '/u01/oracle/oradata/elvis/redo02.log'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

(3)尝试直接修复重做日志文件

SQL> select status from v$instance;

STATUS

------------

MOUNTED

SQL> 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 elvis (thread 1)

ORA-00312: online log 2 thread 1: '/u01/oracle/oradata/elvis/redo02.log'

(4)执行不完全恢复

SQL> show parameter _allow

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

_allow_resetlogs_corruption          boolean     TRUE

这个隐藏参数,小e以前不完全恢复时有说过,在这里就不详述了,可以参见小e以前的恢复笔记

SQL> recover database until cancel;

ORA-00279: change 967170 generated at 10/20/2012 13:57:50 needed for thread 1

ORA-00289: suggestion :

/u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_20/o1_mf_1_10_%u_.arc

ORA-00280: change 967170 for thread 1 is in sequence #10

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

auto

ORA-00308: cannot open archived log

'/u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_20/o1_mf_1_10_%u_.arc'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

ORA-00308: cannot open archived log

'/u01/oracle/flash_recovery_area/ELVIS/archivelog/2012_10_20/o1_mf_1_10_%u_.arc'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

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/oracle/oradata/elvis/system01.dbf'

SQL> alter database open resetlogs;

数据库开启

(4)查看物理文件

[oracle@elvis elvis]$ ll

total 2132364

drwxr-xr-x 2 oracle oinstall      4096 Oct 13 19:49 bak

-rw-r----- 1 oracle oinstall  10076160 Oct 20 15:08 control01.ctl

-rw-r----- 1 oracle oinstall  52429312 Oct 20 15:08 redo01.log

-rw-r----- 1 oracle oinstall 52429312 Oct 20 15:08 redo02.log  --恢复的文件

-rw-r----- 1 oracle oinstall  52429312 Oct 20 14:53 redo02.log.bak

-rw-r----- 1 oracle oinstall  52429312 Oct 20 15:08 redo03.log

-rw-r----- 1 oracle oinstall 629153792 Oct 20 15:08 sysaux01.dbf

-rw-r----- 1 oracle oinstall 734011392 Oct 20 15:08 system01.dbf

-rw-r----- 1 oracle oinstall  71311360 Oct 20 14:20 temp01.dbf

-rw-r----- 1 oracle oinstall  52436992 Oct 20 15:08 test01.dbf

-rw-r----- 1 oracle oinstall 524296192 Oct 20 15:08 undotbs02.dbf

-rw-r----- 1 oracle oinstall   5251072 Oct 20 15:08 users01.dbf

总结:联机重做日志文件的保护对于数据完整至关重要。而因为重做日志文件是动态的无法备份,那该怎么办呢?那就是:冗余。而且一定要跨磁盘冗余。

 

到这里《[小e笔记]之一步一步学习用户管理的备份恢复笔记》就告一段落了,谢谢同学们对小e的支持,在这些案例中难免有错误之处,敬请谅解,欢迎同学们给予留言和指导,小e感激不尽!!!

 

elvis
2012.10.20
知识共享~共同进步
转载请注明:

 http://blog.csdn.net/elvis_dataguru/article/details/8093108

你可能感兴趣的:(thread,oracle,数据库,File,application,database)