Oracle中修復(fù)數(shù)據(jù)塊的損壞
1、先創(chuàng)建一個用于實驗的表空間
create tablespace block datafile size 1M extent management local–因為是11g所以使用了AMS
alter user ff default tablespace block;
alter user ff quota unlimited on block;
2、損壞數(shù)據(jù)文件
關(guān)閉database后用編輯器隨便修改幾個字符,然后啟動database
當(dāng)訪問相關(guān)被損壞的block時,將會遇到錯誤
3、對此使用dbv檢查數(shù)據(jù)文件
dbv file=block.dbf blocksize=8192
假設(shè)獲得第35塊被損壞了
4、恢復(fù)步驟
①select tablespace_name, segment_type, owner, segment_name from dba_extents where file_id=4 and 35 between block_id and block_id+blocks-1;
如果確定損失的是數(shù)據(jù),就ok
設(shè)置內(nèi)部事件,設(shè)置在全表掃描時跳過損壞的數(shù)據(jù)塊
alter system set events=’10231 trace name context forever,level 10′;
隨后,可以用exp和imp進(jìn)行導(dǎo)入導(dǎo)出,進(jìn)行恢復(fù)。但這畢竟導(dǎo)致相依blocks中數(shù)據(jù)的丟失。
②rman的塊媒體恢復(fù)(BMR)
使用BMR恢復(fù)可以大量降低恢復(fù)的時間,可以使datafile仍然處于在線的狀態(tài)。RMAN在BMR恢復(fù)時,先在full或level 0的備份集中查詢相應(yīng)的塊的內(nèi)容,并恢復(fù),隨后使用 redo log進(jìn)行恢復(fù),而不使用level 1備份集。
在恢復(fù)之前,首先要查找到corrupt blocks:在db中,v$database_block_corruption 視圖顯示了rman、analyze、dbv和sql查詢等操作中獲悉的corrupt block信息。此視圖記錄的記錄數(shù)據(jù)有兩類:
*物理的corruption:無法辨識該數(shù)據(jù)塊,checksum、header、footer校驗錯誤
*邏輯corruption:chechsum、header、footer校驗是正確的,但是該數(shù)據(jù)塊的內(nèi)容時不一致的。
注意:BMR是不能用于恢復(fù)邏輯上的corruption的。在backup命令中checksum的校驗是
默認(rèn)開啟的,可以通過NOCHECKSUM選項屬性關(guān)閉。邏輯的校驗?zāi)J(rèn)是關(guān)閉的,可以
在backup、restore、recover、validate命令中添加CHECK LOGICAL開啟。
@@進(jìn)行BMR的條件
1)target db必須運(yùn)行在歸檔模式下,并以當(dāng)前的控制文件open或mounted
2)If the target database is a standby database, then it must be in a consistent state, recovery cannot be in session, and the backup must be older than the corrupted file.
3)數(shù)據(jù)文件的備份集必須是full或level 0
4)對于BMR,rman只使用已經(jīng)歸檔的redo logs
5)flashback db開啟時,rman可以用flashback logs查找corrupt block在corrupt之前的鏡像,用于恢復(fù),加快恢復(fù)速度。
使用恢復(fù)命令恢復(fù)指定的數(shù)據(jù)塊
相關(guān)文章:
