inactive狀態日誌組檔案損壞的恢復

xfhuangfu發表於2015-07-04
1:丟失inactive狀態的日誌檔案
如果資料庫丟失的是inactive日誌組,由於inactive狀態的日誌組已經完成檢查點,
資料庫不會發生資料丟失,此時只需要透過clear重建該日誌組即可
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         45 CURRENT                 879651   2.8147E+14
         2         44 ACTIVE                  879534       879651
         3         43 INACTIVE                879527       879534
        
SQL> col member for a50;
SQL> select * from v$logfile;
    GROUP# STATUS  TYPE    MEMBER                                             IS_
---------- ------- ------- -------------------------------------------------- ---
         3         ONLINE  /home/oracle/oradata/ora11g/redo03.log             NO
         2         ONLINE  /home/oracle/oradata/ora11g/redo02.log             NO
         1         ONLINE  /home/oracle/oradata/ora11g/redo01.log             NO
         1         ONLINE  /home/oracle/oradata/ora11g/redo01a.log            NO
         2         ONLINE  /home/oracle/oradata/ora11g/redo02a.log            NO
         3         ONLINE  /home/oracle/oradata/ora11g/redo03a.log            NO
6 rows selected.
        
        
2:將原來的日誌組3的兩個檔案做備份,然後刪除
SQL> !cp /home/oracle/oradata/ora11g/redo03.log /home/oracle/oradata/ora11g/redo03.log.bak
SQL> !cp /home/oracle/oradata/ora11g/redo03a.log /home/oracle/oradata/ora11g/redo03a.log.bak
SQL> !rm /home/oracle/oradata/ora11g/redo03.log
SQL> !rm /home/oracle/oradata/ora11g/redo03a.log
SQL>

3:如果資料庫發生多次日誌切換,使用到該日誌組3時候,則資料庫可能馬上崩潰
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         45 CURRENT                 879651   2.8147E+14
         2         44 ACTIVE                  879534       879651
         3         43 INACTIVE                879527       879534
SQL>
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         45 ACTIVE                  879651       879780
         2         44 INACTIVE                879534       879651
         3         46 CURRENT                 879780   2.8147E+14
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         45 ACTIVE                  879651       879780
         2         47 CURRENT                 879812   2.8147E+14
         3         46 ACTIVE                  879780       879812
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         45 ACTIVE                  879651       879780
         2         47 CURRENT                 879812   2.8147E+14
         3         46 ACTIVE                  879780       879812
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         48 CURRENT                 879848   2.8147E+14
         2         47 INACTIVE                879812       879848
         3         46 INACTIVE                879780       879812
SQL>  alter system switch logfile;
(一直沒有反應,資料庫hang住了)
在進行多次切換之後,資料庫hang住了
檢視alter.log檔案(v$diag_info檢視中/home/oracle/product/diag/rdbms/ora11g/ora11g/trace)
有如下詳細資訊
Sat Apr 27 15:52:58 2013
Errors in file /home/oracle/product/diag/rdbms/ora11g/ora11g/trace/ora11g_arc0_907.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/home/oracle/oradata/ora11g/redo03a.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-00312: online log 3 thread 1: '/home/oracle/oradata/ora11g/redo03.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3    

4:另開一個會話,關閉db,然後啟動db,啟動的過程中會報錯
[oracle@sp ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Apr 27 11:08:07 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
SQL>
SQL>
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup
ORACLE instance started.
Total System Global Area 1322467328 bytes
Fixed Size                  1336316 bytes
Variable Size             452987908 bytes
Database Buffers          855638016 bytes
Redo Buffers               12505088 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 741
Session ID: 1 Serial number: 5

SQL>

5:首先啟動到mount狀態
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1322467328 bytes
Fixed Size                  1336316 bytes
Variable Size             452987908 bytes
Database Buffers          855638016 bytes
Redo Buffers               12505088 bytes
Database mounted.
檢視log組的狀態

SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         48 CURRENT                 879848   2.8147E+14
         3         46 INACTIVE                879780       879812
         2         47 INACTIVE                879812       879848

SQL> col member for a50;
SQL> set linesize 200;
SQL> select * from v$logfile;
    GROUP# STATUS  TYPE    MEMBER                                             IS_
---------- ------- ------- -------------------------------------------------- ---
         3         ONLINE  /home/oracle/oradata/ora11g/redo03.log             NO
         2         ONLINE  /home/oracle/oradata/ora11g/redo02.log             NO
         1         ONLINE  /home/oracle/oradata/ora11g/redo01.log             NO
         1         ONLINE  /home/oracle/oradata/ora11g/redo01a.log            NO
         2         ONLINE  /home/oracle/oradata/ora11g/redo02a.log            NO
         3         ONLINE  /home/oracle/oradata/ora11g/redo03a.log            NO
6 rows selected.
SQL>

手動刪除損壞的日誌組3,報錯

SQL> alter database clear logfile group 3;
alter database clear logfile group 3
*
ERROR at line 1:
ORA-00350: log 3 of instance ora11g (thread 1) needs to be archived
ORA-00312: online log 3 thread 1: '/home/oracle/oradata/ora11g/redo03.log'
ORA-00312: online log 3 thread 1: '/home/oracle/oradata/ora11g/redo03a.log'

如果在歸檔模式下,並且損壞的日誌組還沒有完成歸檔,則需要使用clear unarchived 命令強制刪除
SQL> alter database clear unarchived logfile group 3;
Database altered.
(執行完上述命令之後,在/home/oracle/oradata/ora11g/目錄下
又重新自動建立了兩個日誌檔案redo03a.log、redo03.log)
開啟db

SQL>
SQL> alter database open;
Database altered.
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         48 CURRENT                 879848   2.8147E+14
         2         47 INACTIVE                879812       879848
         3          0 UNUSED                  879780       879812
SQL>  select * from v$logfile;
    GROUP# STATUS  TYPE    MEMBER                                             IS_
---------- ------- ------- -------------------------------------------------- ---
         3         ONLINE  /home/oracle/oradata/ora11g/redo03.log             NO
         2         ONLINE  /home/oracle/oradata/ora11g/redo02.log             NO
         1         ONLINE  /home/oracle/oradata/ora11g/redo01.log             NO
         1         ONLINE  /home/oracle/oradata/ora11g/redo01a.log            NO
         2         ONLINE  /home/oracle/oradata/ora11g/redo02a.log            NO
         3         ONLINE  /home/oracle/oradata/ora11g/redo03a.log            NO
6 rows selected.

再次切換日誌組
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         48 ACTIVE                  879848       880139
         2         47 INACTIVE                879812       879848
         3         49 CURRENT                 880139   2.8147E+14
SQL>  alter system switch logfile;
System altered.
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         48 ACTIVE                  879848       880139
         2         50 CURRENT                 880145   2.8147E+14
         3         49 ACTIVE                  880139       880145
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         51 CURRENT                 880150   2.8147E+14
         2         50 ACTIVE                  880145       880150
         3         49 INACTIVE                880139       880145
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,status,first_change#,next_change# from v$log;
    GROUP#  SEQUENCE# STATUS           FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ---------------- ------------- ------------
         1         51 ACTIVE                  880150       880153
         2         50 INACTIVE                880145       880150
         3         52 CURRENT                 880153   2.8147E+14

馬上對資料庫做一次全備份
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28373936/viewspace-1722261/,如需轉載,請註明出處,否則將追究法律責任。

相關文章