oracle日誌錯誤恢復(轉)

BSDLite發表於2007-08-16
oracle日誌錯誤恢復(轉)[@more@]這2天碰到日誌損壞的問題,在網上找了一下,覺得這個不錯於是收錄,供大家參考。


ORA-00320 cannot read file header from log string of thread string
  Cause The file is not available.
  Action Restore the log file.
  ORA-00320 無法從thread1的log1中讀取檔案頭
  原因:檔案已丟失
  解決方案:重新提取日誌檔案。
  ORA-00321 log string of thread string, cannot update log file header
  Cause Cannot write to the log file.
  Action Restore access to the file.
  ORA-00321: 無法更新日誌的檔案頭
  原因:無法寫入該日誌檔案
  解決方案:重新讀取該日誌檔案
  ORA-00312 online log string thread string: 'string'
  Cause This message reports the file name for details of another message.
  Action Other messages will accompany this message. See the associated messages for the appropriate action to take.
  ORA-00312:聯機日誌錯誤
  原因:訊息內容錯亂,為其他訊息的相關描述。
  解決方案:日誌訊息衝突。察看與相關動作匹配的訊息。
  ORA-00313 open failed for members of log group string of thread string
  Cause The online log cannot be opened. The file may not be in the expected location.
  Action Specify the correct redo log file or make the log available, if necessary. Also, see the accompanying messages.
  ORA-00313: 日誌組中資料檔案丟失或出錯
  原因:日誌組中的日誌檔案無法被開啟。
  解決方案:確保讀取日誌檔案路徑的正確性或重建日誌檔案。
  案例一:獲取Oracle錯誤資訊——資料庫和網站崩潰
  錯誤描述:我使用的是Oracle 8.1.7.0.1,得到了如下的錯誤資訊:
  ORA-00320 can not read file header from log 1 thread 1
  ORA-321 ORACLE_HOME Redo1.log
  ORA-27091: skgfqio: unable to queue I/O
  附加資訊:我的作業系統是RedHat Linux ,我想知道如何進行修正才能讓資料庫和我們的網站再一次正常工作。
  解決方案:你的資料庫缺少了一個現在redo日誌。要糾正這個問題,按照以下的步驟在SQL*Plus 或者 SVRMGRL 中進行如下操作:
  1. CONNECT / AS SYSDBA
  2. STARTUP MOUNT
  3. RECOVER DATABASE UNTIL CANCEL;
  4. CANCEL (at first prompt)
  5. ALTER DATABASE OPEN RESETLOGS;
  當你用RESETLOGS啟動資料庫的時候,它會重新建立丟失的線上redo日誌檔案。此時,立即關閉資料庫,並且進行良好的備份!如果你不這樣做的話,你就不能恢復過去的resetlogs操作。
  案例二:日誌損壞
  環境描述:linux 9 oracle9
  錯誤描述:今天不小心把名為redo01.log、redo02.log、redo03.log的三個檔案請空了。
  結果資料庫報錯如下
  ORA-00320: cannot read file header from log 2 of thread 1
  ORA-00312: online log 2 thread 1: '/opt/app/oracle/oradata/actdb/redo02.log'
  ORA-27091: skgfqio: unable to queue I/O
  ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
  Additional information: 1
  Additional information: 1
  如何解決呢?
  解決方案:聯機日誌分為當前聯機日誌和非當前聯機日誌,非當前聯機日誌的損壞是比較簡單的,一般透過clear命令就可以解決問題。
  損壞非當前聯機日誌:
  1、啟動資料庫,遇到ORA-00312 or ORA-00313錯誤,如:
  ORA-00313: open failed for members of log group 4 of thread 1
  ORA-00312: online log 3 thread 1: '/opt/oracle/db04/oradata/ORCL/redo03.log'
  從這裡我們知道日誌組1的資料檔案損壞或丟失了
  從報警檔案可以看到更詳細的資訊
  2、檢視V$log檢視:
  SQL> select group#,sequence#,archived,status from v$log;
  GROUP# SEQUENCE# ARC STATUS
  ---------- ---------- --- ----------------
  1 54 YES INACTIVE
  2 55 NO CURRENT
  3 53 YES INACTIVE
  可以知道,該組是非當前狀態,而且已經歸檔。
  3、用CLEAR命令重建該日誌檔案
  SQL>alter database clear logfile group 3;
  如果是該日誌組還沒有歸檔,則需要用
  SQL>alter database clear unarchived logfile group 3;
  4、開啟資料庫,重新備份資料庫
  SQL>alter database open;
  說明:
  1)、如果損壞的是非當前的聯機日誌檔案,一般只需要clear就可以重建該日誌檔案,但是如果該資料庫處於歸檔狀態但該日誌還沒有歸檔,就
  需要強行clear。
  2)、建議clear,特別是強行clear後作一次資料庫的全備份。
  3)、此方法適用於歸檔與非歸檔資料庫。
  損壞當前聯機日誌:
  歸檔模式下當前日誌的損壞有兩種情況,
  一、是資料庫是正常關閉,日誌檔案中沒有未決的事務需要例項恢復,當前日誌組的損壞就可以直接用alter database clear unarchived
  logfile group n來重建。
  二、是日誌組中有活動的事務,資料庫需要媒體恢復,日誌組需要用來同步,有兩種補救辦法
  A. 最好的辦法就是透過不完全恢復,可以保證資料庫的一致性,但是這種辦法要求在歸檔方式下,並且有可用的備份
  B. 透過強制性恢復,但是可能導致資料庫不一致。
  下面分別用來說明這兩種恢復方法
  1 透過備份來恢復
  1、開啟資料庫,會遇到一個類似的錯誤
  ORA-00313: open failed for members of log group 1 of thread 1
  ORA-00312: online log 1 thread 1: 'D:ORACLEORADATATESTREDO01.LOG'
  ORA-27041: unable to open file
  OSD-04002: unable to open file
  O/S-Error: (OS 2) 系統找不到指定的檔案
  2、檢視V$log,發現是當前日誌
  SQL> select group#,sequence#,archived,status from v$log;
  GROUP# SEQUENCE# ARCHIVED STATUS
  ---------- ---------- -------- ----------------
  1 1 NO CURRENT
  2 2
  YES INACTIVE
  3 3 YES INACTIVE
  3、發現clear不成功
  SQL> alter database clear unarchived logfile group 1;
  alter database clear unarchived logfile group 1
  *
  ERROR at line 1:
  ORA-01624: log 1 needed for crash recovery of thread 1
  ORA-00312: online log 1 thread 1: 'D:ORACLEORADATATESTREDO01.LOG'
  4、複製有效的資料庫的全備份,並不完全恢復資料庫
  可以採用獲取最近的SCN的辦法用until scn恢復或用until cnacel恢復
  recover database until cancel
  先選擇auto,儘量恢復可以利用的歸檔日誌,然後重新
  recover database until cancel
  這次輸入cancel,完成不完全恢復,也就是說恢復兩次。
  如:
  SQL> recover database until cancel;
  Auto
  ……
  SQL> recover database until cancel;
  Cancel;
  5、利用alter database open resetlogs開啟資料庫
  說明:
  1、這種辦法恢復的資料庫是一致的不完全恢復,會丟失當前聯機日誌中的事務資料
  2、這種方法適合於歸檔資料庫並且有可用的資料庫全備份。
  3、恢復成功之後,記得再做一次資料庫的全備份。
  4、建議聯機日誌檔案一定要實現鏡相在不同的磁碟上,避免這種情況的發生,因為任何資料的丟失對於生產來說都是不容許的。
  如果沒有備份,進行強制性恢復
  1、開啟資料庫,會遇到一個類似的錯誤
  ORA-00313: open failed for members of log group 1 of thread 1
  ORA-00312: online log 1 thread 1: 'D:ORACLEORADATATESTREDO01.LOG'
  ORA-27041: unable to open file
  OSD-04002: unable to open file
  O/S-Error: (OS 2) 系統找不到指定的檔案
  2、檢視V$log,發現是當前日誌
  SQL> select group#,sequence#,archived,status from v$log;
  GROUP# SEQUENCE# ARCHIVED STATUS
  ---------- ---------- -------- ----------------
  1 1 NO CURRENT
  2 2 YES INACTIVE
  3 3 YES INACTIVE
  3、發現clear不成功
  SQL> alter database clear unarchived logfile group 1;
  alter database clear unarchived logfile group 1
  *
  ERROR at line 1:
  ORA-01624: log 1 needed for crash recovery of thread 1
  ORA-00312: online log 1 thread 1: 'D:ORACLEORADATATESTREDO01.LOG'
  4、把資料庫down掉
  SQL>shutdown immediate
  5、在init.ora中加入如下引數
  _allow_resetlogs_corruption=TRUE
  6、重新啟動資料庫,利用until cancel恢復
  SQL>recover database until cancel;
  Cancel
  如果出錯,不再理會,發出
  SQL>alter database open resetlogs;
  7、資料庫被開啟後,馬上執行一個full export
  8、shutdown資料庫,去掉_all_resetlogs_corrupt引數
  9、重建庫
  10、import並完成恢復
  11、建議執行一下ANALYZE TABLE ...VALIDATE STRUCTURE CASCADE;
  說明:
  1、該恢復方法是沒有辦法之後的恢復方法,一般情況下建議不要採用,因為該方法可能導致資料庫的不一致
  2、該方法也丟失資料,但是丟失的資料沒有上一種方法的資料多,主要是未寫入資料檔案的已提交或未提交資料。
  3、建議成功後嚴格執行以上的7到11步,完成資料庫的檢查與分析
  4、全部完成後做一次資料庫的全備份
  5、建議聯機日誌檔案一定要實現鏡相在不同的磁碟上,避免這種情況的發生,因為任何資料的丟失對於生產來說都是不容許的。

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

相關文章