Oracle資料庫線上重做日誌被刪除的幾種恢複方法

來源:互聯網
上載者:User

標籤:redo 故障處理 oracle

Oracle資料庫的線上重做日誌中包含了資料庫中所有資料的操作記錄,我們可以利用重做日誌做很多的操作,例如日誌挖掘。

有時候,因為種種原因,我們的線上日誌被人誤刪除或者意外損壞掉,我們應該如何進行恢複呢,其實很簡單,看下面內容:

我們通過刪除線上日誌類比日誌被誤刪除的情況:

[[email protected] orcl]$ rm redo*[[email protected] orcl]$ ls -l redo*ls: 無法訪問redo*: 沒有那個檔案或目錄[[email protected] orcl]$ sqlplus / as sysdbaSQL> startup mountORACLE 常式已經啟動。。。。資料庫裝載完畢。

因為我們只是缺失線上重做日誌,所以資料庫是可以啟動到mount狀態的,mount狀態的資料庫只會開啟控制檔案,並不會去校正每個資料檔案的狀態,校正動作會在open階段進行。

SQL> alter database open;alter database open*第 1 行出現錯誤:ORA-03113: 通訊通道的檔案結尾進程 ID: 4607會話 ID: 125 序號: 5

開啟資料庫的話,會報錯,並且資料庫會強行關閉

下面我們使用resetlogs的方法嘗試開啟資料庫:

SQL> recover database until cancel;完成介質恢複。SQL> alter database open;alter database open*第 1 行出現錯誤:ORA-01589: 要開啟資料庫則必須使用 RESETLOGS 或 NORESETLOGS 選項SQL> alter database open resetlogs;資料庫已更改。

resetlogs開啟資料庫必須在資料庫不完全恢複之後才可以用,而且在不完全恢複後必須使用 RESETLOGS 或 NORESETLOGS 選項


除了這種方法以外,我們還可以通過清除logfile的方法進行開啟資料庫,如下:

首先將資料庫啟動到mount狀態

查詢v$log視圖:

SQL> select * from v$log;    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE  MEMBERS ARC STATUS       FIRST_CHANGE# FIRST_TIME  NEXT_CHANGE# NEXT_TIME---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ ------------------- 1    1       1  134217728   5121 NO  CURRENT      984719 2015-09-16 16:04:30   2.8147E+14 3    1       0  134217728   5121 YES UNUSED   0          0 2    1       0  134217728   5121 YES UNUSED   0          0

如果ARCHIVED欄位是YES的話,我們可以通過

alter database clear logfile 命令進行清除,如果是No的話,我們可以通過alter database clear unarchived logfile 進行強行清除SQL> alter database clear logfile group 2;資料庫已更改。SQL> alter database clear logfile group 3;資料庫已更改。SQL> alter database clear unarchived logfile group 1;alter database clear unarchived logfile group 1*第 1 行出現錯誤:ORA-01624: 日誌 1 是緊急恢複執行個體 orcl (線程 1) 所必需的ORA-00312: 聯機日誌 1 線程 1: ‘/app/oradata/orcl/redo01.log‘

但是由於group 1是當前的線上日誌,再加上之前我是使用的 shutdown abort進行關閉的資料庫

資料檔案狀態不一致,需要使用當前日誌進行執行個體恢複,所以無法通過清除日誌命令進行清除

如果資料庫檔案狀態一致,做到這裡我們就可以通過 alter database open命令開啟資料庫了,但是如果碰到這樣的不一致的情況,還需要通過 resetlogs開啟資料庫,如下:

SQL> recover database until cancel;ORA-00279: 更改 984722 (在 09/16/2015 16:04:43 產生) 對於線程 1 是必需的ORA-00289: 建議: /app/archivelog/orcl_1_1_890582670.dbfORA-00280: 更改 984722 (用於線程 1) 在序列 #1 中指定日誌: {<RET>=suggested | filename | AUTO | CANCEL}AUTOORA-00308: cannot open archived log ‘/app/archivelog/orcl_1_1_890582670.dbf‘ORA-27037: unable to obtain file statusLinux-x86_64 Error: 2: No such file or directoryAdditional information: 3ORA-00308: cannot open archived log ‘/app/archivelog/orcl_1_1_890582670.dbf‘ORA-27037: unable to obtain file statusLinux-x86_64 Error: 2: No such file or directoryAdditional information: 3ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error belowORA-01194: file 1 needs more recovery to be consistentORA-01110: data file 1: ‘/app/oradata/orcl/system01.dbf‘SQL> recover database until cancel  ORA-00279: 更改 984722 (在 09/16/2015 16:04:43 產生) 對於線程 1 是必需的ORA-00289: 建議: /app/archivelog/orcl_1_1_890582670.dbfORA-00280: 更改 984722 (用於線程 1) 在序列 #1 中指定日誌: {<RET>=suggested | filename | AUTO | CANCEL}CANCELORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error belowORA-01194: file 1 needs more recovery to be consistentORA-01110: data file 1: ‘/app/oradata/orcl/system01.dbf‘ORA-01112: 未啟動介質恢複SQL> alter database open resetlogs;alter database open resetlogs*第 1 行出現錯誤:ORA-01194: 檔案 1 需要更多的恢複來保持一致性ORA-01110: 資料檔案 1: ‘/app/oradata/orcl/system01.dbf‘

但是我們發現,不完全恢複是失敗的,這個時候通過 resetlogs開啟資料庫也是不可能的,那麼我們只能通過應用隱含參數,通過隱含參數使狀態不一致的資料庫開啟,如下:

SQL> create pfile=‘/home/oracle/p2.ora‘ from spfile;在pfile裡面增加*._allow_resetlogs_corruption=TRUEecho "*._allow_resetlogs_corruption=TRUE">>p2.ora然後通過我們建立的pfile開啟資料庫到mount狀態:SQL> startup mount pfile=‘/home/oracle/p2.ora‘ORACLE 常式已經啟動。Total System Global Area  334036992 bytesFixed Size    2253024 bytesVariable Size  171970336 bytesDatabase Buffers  155189248 bytesRedo Buffers    4624384 bytes資料庫裝載完畢。然後通過 resetlogs的方法開啟資料庫SQL> alter database open resetlogs;資料庫已更改。

因為我們是用我們臨時產生的pfile進行啟動的,所以還要完成最後一步,重啟資料庫即可

好了,資料庫開啟了,但是因為我們的資料庫從異常情況下恢複過來,可能是會有問題的,所以建議做好備份,以防資料丟失。


本文出自 “資料庫之路” 部落格,請務必保留此出處http://dbaway.blog.51cto.com/7099215/1695387

Oracle資料庫線上重做日誌被刪除的幾種恢複方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.