溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Oracle數(shù)據(jù)庫UNDO損壞后的恢復(fù)是怎樣的

發(fā)布時間:2021-11-30 09:27:27 來源:億速云 閱讀:264 作者:柒染 欄目:關(guān)系型數(shù)據(jù)庫

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)Oracle數(shù)據(jù)庫UNDO損壞后的恢復(fù)是怎樣的,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

    UNDO表空間存儲著DML操作數(shù)據(jù)塊的前鏡像數(shù)據(jù),在數(shù)據(jù)回滾,一致性讀,閃回操作,實例恢復(fù)的時候都可能用到UNDO表空間中的數(shù)據(jù)。如果在生產(chǎn)過程中丟失或破壞了UNDO表空間,可能導(dǎo)致某些事務(wù)無法回滾,數(shù)據(jù)庫無法恢復(fù)到一致性的狀態(tài),Oracle實例可能宕機(jī),之后實例無法正常啟動;如果有多個UNDO表空間數(shù)據(jù)文件,丟失其中一個數(shù)據(jù)文件數(shù)據(jù)庫實例可能不會導(dǎo)致實例宕機(jī),數(shù)據(jù)庫無法干凈的關(guān)閉(只能SHUTDOWN ABORT),數(shù)據(jù)庫實例能正常的重啟,但所有未回滾的數(shù)據(jù)塊依然無法處理,嘗試新建UNDO表空間、exp、expdp等操作都會收到ORA-604, ORA-376, and ORA-1110的報錯,下面通過一個實際的案例討論如何處理UNDO損壞后的恢復(fù)。

    客戶的某系統(tǒng)數(shù)據(jù)庫運(yùn)行在HP-UX服務(wù)器上,數(shù)據(jù)庫版本10.2.0.5,單機(jī)數(shù)據(jù)庫,數(shù)據(jù)庫運(yùn)行在非歸檔模式,數(shù)據(jù)庫文件存放在裸設(shè)備上。由于操作系統(tǒng)某文件系統(tǒng)空間不夠,維護(hù)工程師準(zhǔn)備擴(kuò)展該文件系統(tǒng)的大小,由于在生產(chǎn)時段的一個誤操作(誤以為不會影響系統(tǒng)運(yùn)行的一個操作)導(dǎo)致文件系統(tǒng)不能正常工作,卸載之后無法掛載,不巧的是不知道是誰之前為數(shù)據(jù)庫的UNDO表空間和TEMP表空間都添加了一個數(shù)據(jù)文件到該文件系統(tǒng)下。這個操作導(dǎo)致某些事務(wù)掛起無法回滾,數(shù)據(jù)庫不能正常關(guān)閉,但能成功重啟,重啟后事務(wù)依然存在,回滾段顯示狀態(tài)依然ONLINE,嘗試新建UNDO表空間收到ORA-604, ORA-376, and ORA-1110,也無法執(zhí)行exp、expdp操作,告警日志一直在報ORA-604, ORA-376, and ORA-1110的錯誤。

    出現(xiàn)這種情況首先我們要確定是否有事務(wù)受到影響,確定影響范圍,之后嘗試恢復(fù)丟失的數(shù)據(jù)文件(如果在歸檔模式利用備份和歸檔、在線日志恢復(fù)丟失的文件),但該客戶的數(shù)據(jù)庫運(yùn)行在非歸檔模式,無法對數(shù)據(jù)文件進(jìn)行恢復(fù)操作。備份重于一切,一切工作都要圍繞數(shù)據(jù)安全來開展!

下面是處理過程:
   
    我們的基本思維應(yīng)該是新建一個UNDO表空間替換現(xiàn)有的UNDO表空間,UNDO表空間數(shù)據(jù)文件的丟失導(dǎo)致某些事務(wù)無法回滾,數(shù)據(jù)庫的某些數(shù)據(jù)塊不一致(可以認(rèn)為被邏輯損壞),但我們可以接受部分塊的損壞,恢復(fù)過程需要多次重啟數(shù)據(jù)庫實例。

如果你的數(shù)據(jù)庫還能干凈的關(guān)閉,但在正常情況下無法新建UNDO表空間,那么執(zhí)行以下的步驟:

I.A. THE DATABASE WAS CLEANLY SHUT DOWN 
--------------------------------------- 
 
If you are ABSOLUTELY POSITIVE that the database was cleanly shutdown, 
i.e., it was closed with either shutdown NORMAL or IMMEDIATE, then 
the simplest solution is to offline drop the missing datafile, open the 
database in restricted mode, and then drop and recreate the undo  
tablespace to which the file belonged.  DO NOT follow this procedure 
if the database was shut down ABORT or if it crashed. 
 
The steps are: 
 
1. Make sure the database was last cleanly shut down. 
 
   Check the alert.log file for this instance.  Go to the bottom of 
   the file and make sure the last time you shut the database down 
   you got the messages: 
 
        "Shutting down instance (immediate)" 

   OR

"alter database close normal  
         Completed: alter database close normal"

   This also includes the case of a clean shutdown followed by a 
   failed attempt to startup the database.  In that case, Oracle will 
   issue error messages and shut itself down abort.  For the purposes 
   of this solution, though, this counts as a clean shutdown. 
 
   If that is not the case, i.e., if the last time YOU shut the database 
   down it was in abort mode, or the database crashed itself, it is 
   NOT safe to proceed.  You should follow the instructions for 
   case I.B below. 
 
2. If using automatic UNDO_MANAGEMENT, comment out this entry from the parameter 
   file, or set it to MANUAL.  

   將UNDO_MANAGEMENT修改為MANUAL是因為UNDO表空間在自動管理模式下,如果不能成功新建回滾段(后面會DROP現(xiàn)有表空間)將導(dǎo)致數(shù)據(jù)庫實例宕機(jī)。

   If using rollback segments, remove all the rollback segments in the 
   tablespace to which the lost datafile belongs from the ROLLBACK_SEGMENTS 
   parameter in the init.ora file for this instance.  If you are not sure about which rollbacks are 
   in that tablespace, simply comment out the whole ROLLBACK_SEGMENTS entry. 
 
3. Mount the database in restricted mode. 
 
   SQL> STARTUP RESTRICT MOUNT 
   以RESTRICT模式啟動實例是避免在處理過程中有其他客戶端連接。
 
4. Offline drop the lost datafile. 
 
   SQL> ALTER DATABASE DATAFILE '<full_path_file_name>' OFFLINE DROP; 
 
5. Open the database. 
 
   SQL> ALTER DATABASE OPEN 
 
   You should receive the message "Statement processed,".  

   If instead you get ORA-604, ORA-376, and ORA-1110, it is likely the shutdown
   was not normal/immediate.  Review the rest of the options available and/or 
   contact Oracle Support Services.   
 
6. Drop the undo tablespace or tablespace which contains rollback segments
   to which the datafile belonged. 
 
   SQL> DROP TABLESPACE <tablespace_name> INCLUDING CONTENTS; 
 
7. Recreate the undo tablespace.  If using rollback segments, recreate the 
   rollback segment tablespace and all it's rollback segments.  Remember to 
   bring the rollbacks online after you create them. 

  SQL> CREATE TABLESPACE UNDOTBS2 DATAFILE <datafile_name> SIZE 1G AUTOEXTEND ON NEXT 100M;

8. Edit the parameter file setting:
   UNDO_MANAGEMENT=AUTO
   UNDO_TABLESPACE=<new undo tablespace name> 
  
   If using rollback segments, reinclude the rollbacks you just recreated in 
   the ROLLBACK_SEGMENTS parameter in the init.ora file for this instance. 
   As rollback segments were brought online in step #7, no need to proceed 
   with shutdown/startup as needed for undo tablespace.  All that is required
   is:

   SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION; 

如果你的數(shù)據(jù)庫不能正常關(guān)閉,只需要在重啟數(shù)據(jù)庫實例之前將下面的參數(shù)加到參數(shù)文件:
_allow_resetlogs_corruption=TRUE
_offline_rollback_segments="_SYSSMU1$"
_offline_rollback_segments="_SYSSMU2$"
_offline_rollback_segments="_SYSSMU3$"
_offline_rollback_segments="_SYSSMU4$"
_offline_rollback_segments="_SYSSMU5$"
_offline_rollback_segments="_SYSSMU6$"
_offline_rollback_segments="_SYSSMU7$"
_offline_rollback_segments="_SYSSMU8$"
_offline_rollback_segments="_SYSSMU9$"
_offline_rollback_segments="_SYSSMU10$"
_corrupted_rollback_segments="_SYSSMU1$"
_corrupted_rollback_segments="_SYSSMU2$"
_corrupted_rollback_segments="_SYSSMU3$"
_corrupted_rollback_segments="_SYSSMU4$"
_corrupted_rollback_segments="_SYSSMU5$"
_corrupted_rollback_segments="_SYSSMU6$"
_corrupted_rollback_segments="_SYSSMU7$"
_corrupted_rollback_segments="_SYSSMU8$"
_corrupted_rollback_segments="_SYSSMU9$"
_corrupted_rollback_segments="_SYSSMU10$"

    rollback_segments的具體值可以從v$rollname中獲得。
    處理完成后停止數(shù)據(jù)庫實例,去掉以上參數(shù),修改好UNDO相關(guān)參數(shù)即可正常啟動數(shù)據(jù)庫實例,之后再手動處理TEMP表空間丟失的TEMP數(shù)據(jù)文件。
    雖然數(shù)據(jù)庫實例能夠正常啟動,也恢復(fù)了UNDO表空間的使用,但這并不代表不一致的塊已經(jīng)恢復(fù),執(zhí)行某些查詢的時候可能會收到報錯,數(shù)據(jù)庫完全恢復(fù)正常后應(yīng)該立即執(zhí)行一次邏輯備份+物理備份,確保數(shù)據(jù)庫的安全。

上述就是小編為大家分享的Oracle數(shù)據(jù)庫UNDO損壞后的恢復(fù)是怎樣的了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI