试验一:用命令清空日志组方法
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 al