檢測Oracle資料庫壞塊的方法
檢測Oracle資料庫壞塊的辦法:
1、使用DBV(DB File Verify)工具;
2、使用RMAN(Recovery Manager)工具;
DBV(DB File Verify)工具:
外部命令,物理介質資料結構完整性檢查;
只能用於資料檔案(offline或online),不支援控制檔案和重做記錄檔的塊檢查;
也可以驗證備份檔案(rman的copy命令備份或作業系統CP命令備份);
進入盤符,然後執行以下指令碼:
D:\app\Administrator\oradata\orcl>dbv file=ZL9MTLBASE.DBF blocksize=8192;
RMAN(Recovery Manager)工具:
邏輯資料結構完整性檢查;
線上使用Recovery Manager掃描壞塊和備份時,需要資料庫運行在歸檔模式(archive log),否則只能在資料庫未開啟(mount)的情況下進行;
RMAN>backup check logical validate datafile n ;
以上命令可以檢查資料檔案是否包含壞塊,同時並不產生實際的備份輸出。
而且當使用Recovery Manager進行實際的Database Backup時,同時也就進行了壞塊檢查。
直接使用RMAN的命令:backup validate check logical database;
結合V$DATABASE_BLOCK_CORRUPTION視圖更方便。
1)、rman target / nocatalog
2)、RMAN> spool log to 'd:/dbbak/rmanlog.log';---指定輸出rman記錄檔
RMAN> run {
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup validate check logical database;
};
3)、select * from V$DATABASE_BLOCK_CORRUPTION;
4) 、--If V$DATABASE_BLOCK_CORRUPTION contains rows please run this query to find the objects that contains the corrupted blocks:
SELECT e.owner,
e.segment_type,
e.segment_name,
e.partition_name,
c.file#,
greatest(e.block_id, c.block#) corr_start_block#,
least(e.block_id + e.blocks - 1, c.block# + c.blocks - 1) corr_end_block#,
least(e.block_id + e.blocks - 1, c.block# + c.blocks - 1) -
greatest(e.block_id, c.block#) + 1 blocks_corrupted,
null description
FROM dba_extents e, v$database_block_corruption c
WHERE e.file_id = c.file#
AND e.block_id <= c.block# + c.blocks - 1
AND e.block_id + e.blocks - 1 >= c.block#
UNION
SELECT s.owner,
s.segment_type,
s.segment_name,
s.partition_name,
c.file#,
header_block corr_start_block#,
header_block corr_end_block#,
1 blocks_corrupted,
'Segment Header' description
FROM dba_segments s, v$database_block_corruption c
WHERE s.header_file = c.file#
AND s.header_block between c.block# and c.block# + c.blocks - 1
UNION
SELECT null owner,
null segment_type,
null segment_name,
null partition_name,
c.file#,
greatest(f.block_id, c.block#) corr_start_block#,
least(f.block_id + f.blocks - 1, c.block# + c.blocks - 1) corr_end_block#,
least(f.block_id + f.blocks - 1, c.block# + c.blocks - 1) -
greatest(f.block_id, c.block#) + 1 blocks_corrupted,
'Free Block' description
FROM dba_free_space f, v$database_block_corruption c
WHERE f.file_id = c.file#
AND f.block_id <= c.block# + c.blocks - 1
AND f.block_id + f.blocks - 1 >= c.block#
order by file#, corr_start_block#;
5)、
SELECT tablespace_name, segment_type, owner, segment_name
FROM dba_extents
WHERE file_id = &fileid
and &blockid between block_id AND block_id + blocks - 1;
警示日誌中快速識別:
遇到壞塊問題時,資料庫的異常表現通常有:
報告ORA-01578錯誤。
報告ORA-1110錯誤。
報告ORA-00600錯誤。其中,第一個參數為2000-8000,Cache layer 2000 – 4000,Transaction layer 4000 – 6000,Data layer 6000 - 8000。
Trace檔案中出現Corrupt block dba: 0x160c5958 . found。 分析對象失敗。
後台進程,如DBWR,LGWR出現長時間異常等待,如LGWR wait for redo copy。