Oracle数据库联机日志文件丢失处理方法

2/9/2008来源:Oracle教程人气:7275

    试验一:用命令清空日志组方法

 
1、查看原来表中数据SQL>; conn test/test Connected. SQL>; select * from test;     TEL ----------     1 2 3 2、插入新数据SQL>; insert into test values(4);1 row created. SQL>; commit;Commit complete. SQL>;3、        正常关闭数据库4、        利用os command删除所有redo文件5、        启动数据库SQL>; startup Oracle instance started. Total System Global Area  353862792 bytes Fixed Size                   730248 bytes Variable Size             285212672 bytes Database Buffers           67108864 bytes Redo Buffers                 811008 bytes Database mounted. ORA-00313: open failed for members of log group 1 of thread 1 ORA-00312: online log 1 thread 1: '/T3/ORACLE/oradata/ORA9/redo01.log' 6、        查看当前日志状态SQL>; select * from v$log;     GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS ---------- ---------- ---------- ---------- ---------- --- ----------------     FIRST_CHANGE# FIRST_TIME ------------- ----------     1          1          2  104857600          1 YES INACTIVE 487837 01-9月 -05     2          1          4  104857600          1 NO  CURRENT 487955 01-9月 -05     3          1          3  104857600          1 YES INACTIVE 487839 01-9月 -05看来redo01.log不是当前日志,对于这类非当前日志可以直接clear,系统会重新自动生成一个redo文件     7、SQL>; alter database clear logfile group 1;Database altered. 7、        继续启动db SQL>; alter database open;alter database open * ERROR at line 1:ORA-00313: open failed for members of log group 2 of thread 1 ORA-00312: online log 2 thread 1: '/T3/ORACLE/oradata/ORA9/redo02.log' 8、        看来redo也得恢复,但是redo02是当前redo,直接clear是不行的SQL>; alter database clear logfile group 2;alter database clear logfile group 2 * ERROR at line 1:ORA-00350: log 2 of thread 1 needs to be archived ORA-00312: online log 2 thread 1: '/T3/ORACLE/oradata/ORA9/redo02.log'尝试clear unarchived logfile group ,报错:SQL>; alter database clear unarchived logfile group 2;alter database clear unarchived logfile group 2 * ERROR at line 1:ORA-00313: open failed for members of log group 2 of thread 1 ORA-00312: online log 2 thread 1: '/T3/ORACLE/oradata/ORA9/redo02.log' ORA-27037: unable to oBTain file status SVR4 Error: 2: No sUCh file or Directory Additional information: 3看来他是因为找不到这个文件,从有效的备份中cp一个过来看看SQL>; host cp /T3/ORACLE/oradatabak/redo02* /T3/ORACLE/oradata/ORA9
    SQL>; alter database clear unarchived logfile group 2;     Database altered.搞定………。     9、        按照oracle的某些做法也是可以的SQL>; alter database clear unarchived logfile group 1 unrecoverable datafile;     Database altered.     10、但是对于非当前日志就都可以,下面看看redo03 SQL>;  alter database clear logfile group 3;     Database altered.     结论:假如数据库是正常shutdown,非当前日志都可以直接clear来重新生成,而且不丢失数据,因为正常关闭db,数据已经写入dbf文件了。唯独当前日志不可以,当前日志必须首先从有效的备份中拷贝一个日志文件过来,然后用alter database clear unarchived logfile group n 或alter database clear unarchived logfile group n,除此之外,还可以用下面的方法来做     方法二:用cancel模式恢复数据库

 
前面的出错提示,步骤都一样,唯独恢复的方法不一样SQL>; startup ORACLE instance started. Total System Global Area  353862792 bytes Fixed Size                   730248 bytes Variable Size             285212672 bytes Database Buffers           67108864 bytes Redo Buffers                 811008 bytes Database mounted. ORA-00313: open failed for members of log group 1 of thread 1 ORA-00312: online log 1 thread 1: '/T3/ORACLE/oradata/ORA9/redo01.log'看看丢失了哪些redo SQL>; host ls /T3/ORACLE/oradarta/ORA9/redo* /T3/ORACLE/oradarta/ORA9/redo*: No such file or directory看来redo都丢了直接recover SQL>; recover database until cancel;Media recovery complete.这个时候redo还没有生成SQL>; host ls /T3/ORACLE/oradata/ORA9/redo* /T3/ORACLE/oradata/ORA9/redo*: No such file or directory启动数据库SQL>; alter database 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.(注重,这里必须用resetlogs,否则会错误的SQL>; alter database open noresetlogs;alter database open noresetlogs * ERROR at line 1:ORA-00313: open failed for members of log group 1 of thread 1 ORA-00312: online log 1 thread 1: '/T3/ORACLE/oradata/ORA9/redo01.log' SQL>;Resetlogs其实就是根据控制文件让系统自动重新生成redo,假如noresetlog的话,就不会重新生成redo,缺少了文件,db自然无法启动)     SQL>;  host ls /T3/ORACLE/oradata/ORA9/redo* /T3/ORACLE/oradata/ORA9/redo01.log  /T3/ORACLE/oradata/ORA9/redo02.log  /T3/ORACLE/oradata/ORA9/redo03.log SQL>;检验SQL>; select * from test.test;     TEL ----------     1 2 3 4 SQL>;数据一点儿都没有丢失     结论:假如数据库是正常关闭的,用recover database until cancel可以轻松恢复或者说重新建立所有的redo,不再区分是否是当前日志,而且由于正常关闭,不会丢失任何数据,唯一可能丢失的情况就是假如日志还没有归档这种恢复方法 由于要resetlogs,所以在恢复完成后,日志清零,以前的备份不再起作用,所以建议立即备份SQL>; archive log list;Database log mode              Archive Mode Automatic archival             Enabled Archive destination            /T3/ORACLE/arch Oldest online log sequence     0 Next log sequence to archive   1 Current log sequence           1 SQL>;
    实验三:通过重新生成控制文件来恢复redo

 
前面的都一样,只是处理方法不一样SQL>; startup ORACLE instance started.     Total System Global Area  353862792 bytes Fixed Size                   730248 bytes Variable Size             285212672 bytes Database Buffers           67108864 bytes Redo Buffers                 811008 bytes Database mounted. ORA-00313: open failed for members of log group 1 of thread 1 ORA-00312: online log 1 thread 1: '/T3/ORACLE/oradata/ORA9/redo01.log'     SQL>; alter database backup controlfile to trace;     Database altered.     SQL>; shutdown immediate ORA-01109: database not open     Database dismounted. ORACLE instance shut down. SQL>;2、        修改一下刚才生成的那个文件CREATE CONTROLFILE REUSE DATABASE "ORA9"  RESETLOGS  ARCHIVELOG——  SET STANDBY TO MAXIMIZE PERFORMANCE MAXLOGFILES 50 MAXLOGMEMBERS 5 MAXDATAFILES 100 MAXINSTANCES 1 MAXLOGHISTORY 226 LOGFILE GROUP 1 '/T3/ORACLE/oradata/ORA9/redo01.log'  SIZE 100M,GROUP 2 '/T3/ORACLE/oradata/ORA9/redo02.log'  SIZE 100M,GROUP 3 '/T3/ORACLE/oradata/ORA9/redo03.log'  SIZE 100M—— STANDBY LOGFILE DATAFILE '/T3/ORACLE/oradata/ORA9/system01.dbf','/T3/ORACLE/oradata/ORA9/undotbs01.dbf','/T3/ORACLE/oradata/ORA9/cwmlite01.dbf','/T3/ORACLE/oradata/ORA9/drsys01.dbf','/T3/ORACLE/oradata/ORA9/example01.dbf','/T3/ORACLE/oradata/ORA9/indx01.dbf','/T3/ORACLE/oradata/ORA9/odm01.dbf','/T3/ORACLE/oradata/ORA9/tools01.dbf','/T3/ORACLE/oradata/ORA9/users01.dbf','/T3/ORACLE/oradata/ORA9/xdb01.dbf','/T3/ORACLE/oradata/ORA9/test01.dbf' CHARACTER SET ZHS16GBK;另存为一个脚本,运行他SQL>; @clone.sql Control file created. SQL>; alter database open resetlogs;Database altered. SQL>;搞定……………     结论:这种方法的要害是重新创建控制文件,后面的步骤和前面的道理一样的     前面的三种方法都是假设db是正常关闭的,数据已经写入数据库文件中,所以不会由数据存在redo种,所以clear的话也不会有数据丢失     方法四:修改系统参数方法1、        插入数据SQL>; select * from test;     TEL ----------     1 2 3 4     SQL>; insert into test values(5);     1 row created.     SQL>; commit;     Commit complete.     SQL>;2、        强行关闭SQL>; shutdown abort ORACLE instance shut down. SQL>;3、        手工模拟删除redo 4、        启动db SQL>; startup ORACLE instance started.
    Total System Global Area  353862792 bytes Fixed Size                   730248 bytes Variable Size             285212672 bytes Database Buffers           67108864 bytes Redo Buffers                 811008 bytes Database mounted. ORA-00313: open failed for members of log group 3 of thread 1 ORA-00312: online log 3 thread 1: '/T3/ORACLE/oradata/ORA9/redo03.log' ORA-27037: unable to obtain file status SVR4 Error: 2: No such file or directory Additional information: 3 5、        尝试使用前3中方法中最简单的SQL>; recover database until cancel;ORA-00279: change 550174 generated at 09/02/2005 16:00:19 needed for thread 1 ORA-00289: suggestion : /T3/ORACLE/arch/1_1.dbf ORA-00280: change 550174 for thread 1 is in sequence #1 Specify log: {<RET>;=suggested filename AUTO CANCEL}看来不行6、        修改init.ora,加入一行_allow_resetlogs_corruption=true 7、        启动with pfile SQL>; startup ORACLE instance started. Total System Global Area  320308312 bytes Fixed Size                   730200 bytes Variable Size             285212672 bytes Database Buffers           33554432 bytes Redo Buffers                 811008 bytes Database mounted. ORA-01589: must use RESETLOGS or NORESETLOGS option for database open     SQL>; host ls /T3/ORACLE/oradata/ORA9/redo* /T3/ORACLE/oradata/ORA9/redo*: No such file or directory SQL>; alter database open resetlogs;Database altered.     SQL>; host ls /T3/ORACLE/oradata/ORA9/redo* /T3/ORACLE/oradata/ORA9/redo01.log  /T3/ORACLE/oradata/ORA9/redo02.log  /T3/ORACLE/oradata/ORA9/redo03.log 8、        检验数据SQL>; select * from test.test;     TEL ----------     1 2 3 4     SQL>;看到了吧,我们前面由于执行了SHUTDOWN ABORT,这时候对数据的修改还没有保存到数据文件中,虽然执行了COMMIT,这个时候还在联机日志中,等待CKPT触发DBWR写入DATAFILE,但是这个时候执行了SHUTDOWN ABORT,redo被删除后,里面的信息也就丢了,造成数据丢失9、        备份,去掉那个参数     试验五:丢失当前日志组的成员1、SQL>; select * from v$logfile;     GROUP# STATUS  TYPE ---------- ------- -------     MEMBER --------------------------------------------------------------------------------     3         ONLINE /T3/ORACLE/oradata/ORA9/redo03.log
    2         ONLINE /T3/ORACLE/oradata/ORA9/redo02.log     1         ONLINE /T3/ORACLE/oradata/ORA9/redo01.log     GROUP# STATUS  TYPE ---------- ------- -------     MEMBER --------------------------------------------------------------------------------     1         ONLINE /T3/ORACLE/oradata/ORA9/redo01a.log     2         ONLINE /T3/ORACLE/oradata/ORA9/redo02a.log     3         ONLINE /T3/ORACLE/oradata/ORA9/redo03a.log     SQL>; select * from v$log;     GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS ---------- ---------- ---------- ---------- ---------- --- ----------------     FIRST_CHANGE# FIRST_TIME ------------- ----------     1          1          2  104857600          2 YES INACTIVE 554599 02-9月 -05     2          1          3  104857600          2 YES INACTIVE 554601 02-9月 -05     3          1          4  104857600          2 NO  CURRENT 554603 02-9月 -05 SQL>;3、        模拟插入数据SQL>; conn test/test Connected. SQL>; select * from test;     TEL ----------     1 2 3 4     SQL>; insert into test values(5);     1 row created.     SQL>; commit 2  ;     Commit complete. 4、shutdown db,模拟删除一个当前日志成员$ cd oradata/ORA9 $ ls redo03* redo03.log   redo03a.log $ rm redo03a.log 5、启动db,表面没有错误SQL>; startup ORACLE instance started.     Total System Global Area  353862792 bytes Fixed Size                   730248 bytes Variable Size             285212672 bytes Database Buffers           67108864 bytes Redo Buffers                 811008 bytes Database mounted. Database opened. SQL>;6、 查看日至成员SQL>; select * from v$logfile;
    GROUP# STATUS  TYPE ---------- ------- -------     MEMBER --------------------------------------------------------------------------------     3         ONLINE /T3/ORACLE/oradata/ORA9/redo03.log     2         ONLINE /T3/ORACLE/oradata/ORA9/redo02.log     1         ONLINE /T3/ORACLE/oradata/ORA9/redo01.log     GROUP# STATUS  TYPE ---------- ------- -------     MEMBER --------------------------------------------------------------------------------     1         ONLINE /T3/ORACLE/oradata/ORA9/redo01a.log     2         ONLINE /T3/ORACLE/oradata/ORA9/redo02a.log     3 INVALID ONLINE /T3/ORACLE/oradata/ORA9/redo03a.log 7、        删除出问题的联机日志文件SQL>; alter database drop logfile member '/T3/ORACLE/oradata/ORA9/redo03a.log';alter database drop logfile member '/T3/ORACLE/oradata/ORA9/redo03a.log' * ERROR at line 1:ORA-01609: log 3 is the current log for thread 1 - cannot drop members ORA-00312: online log 3 thread 1: '/T3/ORACLE/oradata/ORA9/redo03.log' ORA-00312: online log 3 thread 1: '/T3/ORACLE/oradata/ORA9/redo03a.log'     SQL>;看来当前日志成员是不答应删除的SQL>; alter system switch logfile;     System altered.     SQL>; select * from v$log;     GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS ---------- ---------- ---------- ---------- ---------- --- ----------------     FIRST_CHANGE# FIRST_TIME ------------- ----------     1          1          5  104857600          2 NO  CURRENT 557687 02-9月 -05     2          1          3  104857600          2 YES INACTIVE 554601 02-9月 -05     3          1          4  104857600          2 YES ACTIVE 554603 02-9月 -05     SQL>; alter database drop logfile member '/T3/ORACLE/oradata/ORA9/redo03a.log';     Database altered.     SQL>;  alter database add logfile member '/T3/ORACLE/oradata/ORA9/redo03a.log' to group 3;
    Database altered. SQL>; select * from v$logfile;     GROUP# STATUS  TYPE ---------- ------- -------     MEMBER --------------------------------------------------------------------------------     3         ONLINE /T3/ORACLE/oradata/ORA9/redo03.log     2         ONLINE /T3/ORACLE/oradata/ORA9/redo02.log     1         ONLINE /T3/ORACLE/oradata/ORA9/redo01.log     GROUP# STATUS  TYPE ---------- ------- -------     MEMBER --------------------------------------------------------------------------------     1         ONLINE /T3/ORACLE/oradata/ORA9/redo01a.log     2         ONLINE /T3/ORACLE/oradata/ORA9/redo02a.log     3 INVALID ONLINE /T3/ORACLE/oradata/ORA9/redo03a.log看来还得切换一下日至SQL>; alter system switch logfile;     System altered. SQL>; select * from v$logfile;     GROUP# STATUS  TYPE ---------- ------- -------     MEMBER --------------------------------------------------------------------------------     3         ONLINE /T3/ORACLE/oradata/ORA9/redo03.log     2         ONLINE /T3/ORACLE/oradata/ORA9/redo02.log     1         ONLINE /T3/ORACLE/oradata/ORA9/redo01.log     GROUP# STATUS  TYPE ---------- ------- -------     MEMBER --------------------------------------------------------------------------------     1         ONLINE /T3/ORACLE/oradata/ORA9/redo01a.log     2         ONLINE /T3/ORACLE/oradata/ORA9/redo02a.log     3         ONLINE /T3/ORACLE/oradata/ORA9/redo03a.log     至此,大功告成……………。     结论:

 
只要日志组的member不是一个,出现前面的4种可能性是非常小的,即使出现了也有相应的恢复方法,所以不必惊慌;假如memer多于1个,即使坏了其中的几个,也不会 影响数据库的正常启动,启动后,再进行相应的操作即可, 所以这个时候天天察看alert.log就显得非常重要了。