[zt] 如何處理Oracle資料庫中的壞塊[final]

tolywang發表於2010-09-25

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 = and 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,,,,0) from dual;
hi_rid after the corrupt block:
dbms_rowid.rowid_create(1,,,+1,0) from dual;
建一個臨時表
create table salvage_table as select * from corrupt_tab where 1=2;
儲存未損壞的資料
insert into salvage_table select /*+ rowid(a) */ * from a where rowid < ;
insert into salvage_table select /*+ rowid(a) */ * from a where rowid >= ;
重建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(,);
儲存表中資料
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 wner=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=;

怎麼預先發現壞塊:
(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

---

  

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-674775/,如需轉載,請註明出處,否則將追究法律責任。

相關文章