oracle的數據塊有固定的格式和結構,分三層: cache layer、transaction layer和data layer.
對數據塊進行讀寫操作時,做一致性檢查:
–block type
–dba
–scn 
–header and tail 
發現不一致,標記為壞塊。
壞塊有兩種: 物理壞塊和邏輯壞塊。
壞塊產生的影響:數據字典表、回滾段表、臨時段和用戶數據表和索引。
應用報錯:
–ora-1578 
–ora-600 and trace file in bdump directory 
第一個參數[2000]-[8000] 
range                            block layer
 -------------------------------------------
cache layer                 2000 – 4000 
transaction layer       4000 – 6000 
data layer                   6000 - 8000
壞塊產生的原因:
oracle調用標準c的系統函數,對數據塊進行讀寫操作:
- bad i/o, h/w, firmware.
- operating system i/o or caching problems.
- memory or paging problems. 
- disk repair utilities.
- part of a datafile being overwritten.
- third part software incorrectly attempting to access oracle used heap.
- oracle or operating system bug.
表中壞塊的處理方法:
(1).收集相關信息:
ora-1578  file#  (rfn)  block#
ora-1110  file#  (afn)  block#
ora-600   file#  (afn)  block#
select file_name,tablespace_name,file_id “afn”, relative_fno “rfn” from dba_data_files;  
select file_name,tablespace_name,file_id, relative_fno “rfn” from dba_temp_files;
9i tempfiles afn=file_id+value of db_files
(2).確定受影響的對象:
select tablespace_name, segment_type, owner, segment_name, partition_name from dba_extents where file_id = <afn> and <bl> between block_id and block_id + blocks - 1;
if on tempfile, no data return;
(3).根據對象類型,確定處理方法:
objects of sys
rollback
temporary segment
index and index partition
cluster |
partition | ===>表中壞塊的處理
table |
(4).選擇合適的方法搶救表中的數據:
recover datafile
recover block only (9i)
通過rowid range scan 保存數據
使用dbms_repair 
使用event
表中壞塊的處理方法一:恢復數據文件
數據庫為歸檔方式,有完整的物理備份   
offline the affected data file 
alter database datafile 'name_file' offline;
保存有壞塊的文件,restore 備份。
if different from the old location
alter database rename file 'old_name' to 'new_name'; 
recover the datafile
recover datafile 'name_of_file'; 
online the file/s
alter database datafile 'name_of_file' online;
表中壞塊的處理方法二:block recover
要求
(1).數據庫9.2
(2).catalog 和rman
(3).數據庫為歸檔方式,有完整的物理備份
(4).使用rman的blockrecover命令 
rman>run{blockrecover
                     datafile 3 block 4,5;}
可以強制使用某個scn號之前的備份,恢復數據塊。
rman>run{blockrecover
                     datafile 3 block 4,5 restore until sequence 7402;}
表中壞塊的處理方法三:rowid range scan
使用dbms_rowid 確定壞塊的rowid range 
low_rid inside the corrupt block:
select dbms_rowid.rowid_create(1,<obj_id>,<rfn>,<bl>,0) from dual;
hi_rid after the corrupt block:
dbms_rowid.rowid_create(1,<obj_id>,<rfn>,<bl>+1,0) from dual;
建一個臨時表
create table salvage_table as select * from corrupt_tab where 1=2;
保存未損壞的數據
insert into salvage_table select /*+ rowid(a) */ * from <owner.tablename> a where rowid < '<low_rid>';
insert into salvage_table select /*+ rowid(a) */ * from <owner.tablename> a where rowid >= '<hi_rid>';
重建table,index,foreign constrain table.
表中壞塊的處理方法四:add 10231 event
在session 或database級設10231 event,做全表掃描時,可以跳過壞塊.
session level:
alter session set events '10231 trace name context forever,level 10'; 
create table salvage_emp as select * from corrupt_emp; 
database level:
event="10231 trace name context forever, level 10" 
表中壞塊的處理方法五:dbms_repair
標記有壞塊的表,做全表掃描時,可以跳過壞塊.
execute dbms_repair.skip_corrupt_blocks('<schema>','<tablename>'); 
保存表中數據
export the table. 
create table salvage_emp as select * from corrupt_emp;
表中壞塊的處理方法六:檢查索引
檢查表上的索引和primary key foreign key約束
select owner,index_name, index_type from dba_indexes where table_owner=‘xxxx' and table_name='xxxx';
select owner,constraint_name,constraint_type,table_name from dba_constraints where owner='xxx' and table_name='xxx' and
constraint_type='p';
select owner,constraint_name,constraint_type,table_name from dba_constraints where r_owner='xxxx' and r_constraint_name='<constraint-name>'; 
如何預先發現壞塊:
(1).export utility
exp system/manager full=y log=exp_db_chk.log file=/dev/null volsize=100g 
does not detect disk corruptions above the high water mark
does not detect corruptions in indexes
does not detect all corruptions in the data dictionary
analyze table tablename validate structure cascade 
performs the block checks ,but does not mark blocks as corrupt. 
it also checks that table and index entries match. 
any problems found are reported into the user session trace file in user_dump_dest. 
可以定期對一些重要的表作檢查.
(2).dbv檢查數據文件
show parameter  db_block_size 
select bytes/2048 from v$datafile where file#=5; 
dbv file=/dev/rdsk/r1.dbf blocksize=2048 end=5120 
dbv expects a filename extension. if on raw dev
ln -s /dev/rdsk/mydevice /tmp/mydevice.dbf 
now use dbv against /tmp/mydevice.dbf