Oracle的redo log在各场景下的恢复

Oracle的redo log非常重要,redo log损坏将导致数据库开法开启或数据丢失,针对redo log在各种场景下如何打开或恢复数据库,特别模拟测试说明:

各场景包括如下(共6个场景):

场景一.非归档下inactive状态的redo 恢复

场景二.非归档下active状态的redo 恢复

场景三.非归档下current状态的redo恢复

场景四.归档模式下inactive状态的redo 恢复

场景五.归档模式下的active状态的redo 恢复

场景六.归档模式下的current状态的redo恢复

oracle版本为oracle 11.1.0.7

各场景恢复操作如下:

一.非归档下inactive状态的redo 恢复

session 1:
查看归档模式:---非归档
SQL> archive log list
 Database log mode No Archive Mode
 Automatic archival Disabled
 Archive destination /kttest1-1_data1/emsdev/arch
 Oldest online log sequence 3
 Current log sequence 8

查看log情况:

SQL> select * from v$log;

GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
 ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
 1 1 10 104857600 1 NO INACTIVE 1.2790E+13 30-MAY-14
 2 1 13 104857600 1 NO CURRENT 1.2790E+13 30-MAY-14
 3 1 12 104857600 1 NO ACTIVE 1.2790E+13 30-MAY-14

SQL> col member for a70
 SQL> select * from v$logfile;

GROUP# STATUS TYPE MEMBER
 ---------- ------- ------- ----------------------------------------------------------------------
 IS_
 ---
 3 ONLINE /kttest1-1_data1/emsdev/redo03.dbf
 NO

1 ONLINE /kttest1-1_data1/emsdev/redo01.dbf
 NO

2 ONLINE /kttest1-1_data1/emsdev/redo02.dbf
 NO

SQL> alter system checkpoint;

System altered.

SQL> alter system checkpoint;

System altered.


 session 2:
 root@kttest1-1 # dd if=/dev/null of=/kttest1-1_data1/emsdev/redo02.dbf bs=512 count=10
 0+0 records in
 0+0 records out


 session 1:
 SQL> select * from v$log;

GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS
 ---------- ---------- ---------- ---------- ---------- --- ----------------
 FIRST_CHANGE# FIRST_TIM
 ------------- ---------
 1 1 23 104857600 1 NO INACTIVE
 1.2792E+13 03-JUN-14

2 1 22 104857600 1 NO INACTIVE
 1.2792E+13 02-JUN-14

3 1 24 104857600 1 NO CURRENT
 1.2792E+13 03-JUN-14


 SQL> shutdown immediate
 Database closed.
 Database dismounted.
 ORACLE instance shut down.
 SQL> startup
 ORACLE instance started.

Total System Global Area 3207790592 bytes
 Fixed Size 2119072 bytes
 Variable Size 381586016 bytes
 Database Buffers 2818572288 bytes
 Redo Buffers 5513216 bytes
 Database mounted.
 ORA-00320: cannot read file header from log 2 of thread 1
 ORA-00312: online log 2 thread 1: '/kttest1-1_data1/emsdev/redo02.dbf'

SQL> alter database clear logfile group 2;

Database altered.

SQL> alter database open;
 alter database open
 *
 ERROR at line 1:
 ORA-00320: cannot read file header from log 2 of thread 1
 ORA-00312: online log 2 thread 1: '/kttest1-1_data1/emsdev/redo02.dbf'


 SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database open;

Database altered.

SQL> alter database add logfile group 2 ('/kttest1-1_data1/emsdev/redo02.dbf') size 100m;
 alter database add logfile group 2 ('/kttest1-1_data1/emsdev/redo02.dbf') size 300m
 *
 ERROR at line 1:
 ORA-00301: error in adding log file '/kttest1-1_data1/emsdev/redo02.dbf' - file
 cannot be created
 ORA-27038: created file already exists
 Additional information: 1


 SQL> alter database add logfile group 2 ('/kttest1-1_data1/emsdev/redo02.dbf') size 100m reuse;

Database altered.


二.非归档下active状态的redo 恢复

如果非current redo 损坏,但是包含active事务,那么情况完全不同。

----Session 1


 SQL> select * from v$log;

GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS
 ---------- ---------- ---------- ---------- ---------- --- ----------------
 FIRST_CHANGE# FIRST_TIM
 ------------- ---------
 1 1 26 104857600 1 NO CURRENT
 1.2792E+13 04-JUN-14

2 1 25 314572800 1 NO ACTIVE
 1.2792E+13 04-JUN-14

3 1 24 104857600 1 NO INACTIVE
 1.2792E+13 03-JUN-14

SQL> col member for a70
 SQL> select * from v$logfile;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a18f509956a427c366160a3189765dc3.html