恢複
昨天遇到一個Oracle資料庫的問題,環境是:Windows2000+Oracle9i。
使用windows關機重啟後,oracle無法串連,當用startup啟動時總是報ORA-00333錯誤,檢查Oracle文檔對此問題的描述,如下:
ORA-00333 redo log read error block string count string
Cause: An I/O error occurred while reading the log described in the
accompanying error.
Action: Restore accessibility to file, or get another copy of the file.
判斷是聯機日誌損壞了,下面是找到的一篇文章對此問題的解決辦法。
大家都清楚,聯機日誌分為當前聯機日誌和非當前聯機日誌,非當前聯機日誌的損壞是比較簡單的,一般通過clear命令就可以解決問題。
1、啟動資料庫,遇到ORA-00312 or ORA-00313錯誤,如
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\TEST\REDO01.LOG'
從這裡我們知道日誌組1的資料檔案損壞了
從警示檔案可以看到更詳細的資訊
2、查看V$log視圖
SQL> select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS
---------- ---------- -------- ----------------
1 1 YES INACTIVE
2 2 YES INACTIVE
3 3 NO CURRENT
可以知道,該組是非目前狀態,而且已經歸檔。
3、用CLEAR命令重建該記錄檔
SQL>alter database clear logfile group 1;
如果是該日誌組還沒有歸檔,則需要用
SQL>alter database clear unarchived logfile group 1;
4、開啟資料庫,重新備份資料庫
SQL>alter database open;
說明:
1、如果損壞的是非當前的聯機記錄檔,一般只需要clear就可以重建該日誌文
件,但是如果該資料庫處于歸檔狀態但該日誌還沒有歸檔,就需要強行clear。
2、建議clear,特別是強行clear後作一次資料庫的全備份。
3、此方法適用于歸檔與非歸檔資料庫
損壞當前聯機日誌
歸檔模式下當前日誌的損壞有兩種情況,
一、是資料庫是正常關閉,記錄檔中沒有未決的事務需要執行個體恢複,當前日誌組
的損壞就可以直接用alter database clear unarchived logfile group n來重建。
二、是日誌組中有活動的事務,資料庫需要媒體恢複,日誌組需要用來同步,有兩
種補救辦法
A. 最好的辦法就是通過不完全恢複,可以保證資料庫的一致性,但是這種辦法要求
在歸檔方式下,並且有可用的備份
B. 通過強制性恢複,但是可能導致資料庫不一致。
下面分別用來說明這兩種恢複方法
通過備份來恢複
1、開啟資料庫,會遇到一個類似的錯誤
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\TEST\REDO01.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:\ORACLE\ORADATA\TEST\REDO01.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:\ORACLE\ORADATA\TEST\REDO01.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:\ORACLE\ORADATA\TEST\REDO01.LOG'