ITPub博客

首页 > 应用开发 > IT综合 > 坏块快速恢复

坏块快速恢复

原创 IT综合 作者:imlihj2007 时间:2011-05-26 02:42:15 0 删除 编辑

使用10231诊断事件,在做全表扫描的时候跳过坏块
可以在session级别设定:
ALTER SESSION SET EVENTS '10231 TRACE NAME CONTEXT FOREVER, LEVEL 10';
也可以在数据库级别上设定,在初始化参数中加入:event="10231 trace name context forever, level 10" ,
然后重启数据库。

然后从存在坏块的表中取出不存在坏块的数据,执行以下的语句:
CREATE TABLE salvage_emp AS SELECT * FROM corrupt_table;
最后rename生成的corrupt_table为原来表的名字,并重建表上的索引和限制。


使用dbms_repair包进行恢复
使用dbms_repair标记有坏块的表,在做全表扫描的时候跳过坏块,执行以下的语句:
Execute DBMS_REPAIR.SKIP_CORRUPT_BLOCKS('','');
然后使用exp工具或者createtable as select的方法取出没有坏块数据,然后重建表,表上的索引和限制。
begin
dbms_repair.admin_tables(table_name => 'REPAIR_TABLE',
table_type => dbms_repair.repair_table,
action => dbms_repair.create_action,
tablespace => 'USERS');
end;

begin
dbms_repair.admin_tables(table_name => 'ORPHAN_KEY_TABLE',
table_type => dbms_repair.orphan_table,
action => dbms_repair.create_action,
tablespace => 'USERS');
end;

set serveroutput on
declare
v_out_num_corrupt INT;
num_corrupt INT;
begin
num_corrupt :=0;
dbms_repair.check_object(
schema_name => 'JAY',
object_name => 'TBAK',
repair_table_name => 'REPAIR_TABLE',
corrupt_count => v_out_num_corrupt);
dbms_output.put_line('Blocks to be repair:' || to_char(v_out_num_corrupt));
end;

declare
rpr_count int;
begin
rpr_count := 0;
dbms_repair.check_object(schema_name => 'JAY',
object_name => 'TBAK',
repair_table_name => 'REPAIR_TABLE',
corrupt_count => rpr_count);
dbms_output.put_line('repair count: ' || to_char(rpr_count));
end;

declare
fix_count int;
begin
fix_count := 0;
dbms_repair.fix_corrupt_blocks(schema_name => 'JAY',
object_name => 'TBAK',
object_type => dbms_repair.table_object,
repair_table_name => 'REPAIR_TABLE',
fix_count => fix_count);
dbms_output.put_line('fix count: ' || to_char(fix_count));
end;

declare
begin
dbms_repair.skip_corrupt_blocks(schema_name => 'JAY',
object_name => 'TBAK',
object_type => dbms_repair.table_object,
flags => dbms_repair.skip_flag);
end;
 


select * from v$backup_corruption
select * from REPAIR_TABLE
select owner, object_name, object_type from dba_objects where object_name like '%ORPHAN_KEY_TABLE';
select * from ORPHAN_KEY_TABLE

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9879835/viewspace-1050356/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 一些X$表的小结
请登录后发表评论 登录
全部评论

注册时间:2011-05-25

  • 博文量
    109
  • 访问量
    1577027