如果处理Oracle数据库中的坏块问题[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 cn_chenfeng 的 blog

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';

本文关键:如果处理Oracle数据库中的坏块问题
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top