二、丢失当前日志文件的恢复
丢失的日志文件的状态如果是ACTIVE或CURRENT,说明没有归档。如果没有归档的日志组中含有多个日志文件成员,那么丢失或者损坏部分日志文件时,只需要复制正常的日志文件,来替换丢失或损坏的日志文件即可解决,这样数据不会丢失,也不用做恢复操作。
如果没有归档的重做日志组中所有日志件都丢失或者损坏,将会导致数据库数据丢失,如果没有归档的日志文件组为当前组,则数据库立即DOWN机。当这个情况发生时,就意味着数据的丢失,我们只能将数据库恢复到前一次的归档日志切换时刻
下面模拟在正常和非正常关闭数据库后丢失当前日志文件的场景,来恢复日志文件。
1. 正常关闭数据库,丢失当前日志文件的恢复
因为是正常关闭,因此数据库在关闭前,做了全面检查点,日志文件对实例恢复没有意义了。
测试环境
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for Linux: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 – Production
SQL> select group#,members,status from v$log;
GROUP# MEMBERS STATUS
---------- ---------- ----------------
1 2 INACTIVE
2 1 CURRENT
3 2 INACTIVE
模拟丢失文件
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> !rm /u01/oradata1/redo02.log
SQL> startup
ORACLE instance started.
Total System Global Area 146472960 bytes
Fixed Size 1298472 bytes
Variable Size 92278744 bytes
Database Buffers 50331648 bytes
Redo Buffers 2564096 bytes
Database mounted.
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u01/oradata1/redo02.log'
SQL> !ls -l /u01/oradata1
total 102528
-rw-r----- 1 oracle oinstall 52429312 Sep 26 03:49 redo010.log
进行恢复
SQL> alter database clear unarchived logfile group 2;
Database altered.
检查发现,日志文件已恢复。
SQL> !ls -l /u01/oradata1
total 102528
-rw-r----- 1 oracle oinstall 52429312 Sep 26 03:49 redo010.log
-rw-r----- 1 oracle oinstall 52429312 Sep 26 03:54 redo02.log
SQL> alter database open;
Database altered.
2. 异常关闭数据库,丢失当前日志文件的恢复
异常关闭数据库,说明在数据库启动时进行的实例恢复一定要求有当前的日志文件,否则oracle将无法保证提交的成功的数据部丢失。
测试环境
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for Linux: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 – Production
SQL> select group#,members,status from v$log;
GROUP# MEMBERS STATUS
---------- ---------- ----------------
1 2 INACTIVE
2 1 CURRENT
3 2 INACTIVE
模拟丢失文件
SQL> shutdown abort
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> !rm /u01/oradata1/redo02.log
SQL> startup
ORACLE instance started.
Total System Global Area 146472960 bytes
Fixed Size 1298472 bytes
Variable Size 92278744 bytes
Database Buffers 50331648 bytes
Redo Buffers 2564096 bytes
Database mounted.
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u01/oradata1/redo02.log'
SQL> !ls -l /u01/oradata1
total 102528
-rw-r----- 1 oracle oinstall 52429312 Sep 26 03:49 redo010.log
