2)使用dbms_repair.check_object进行坏块检测
SQL> set serveroutput on size 100000;
SQL> declare
2 rpr_count int;
3 begin
4 rpr_count := 0;
5 dbms_repair.check_object(
6 schema_name => 'SYS',--指定对象模式,也就是对象的所有者
7 object_name => 'TEST',--指定对象名,也就是表名
8 repair_table_name => 'REPAIR_TABLE',
9 corrupt_count => rpr_count);
10 dbms_output.put_line('repair block count: '
11 ||to_char(rpr_count));
12 end;
13 /
repair block count: 4
PL/SQL 过程已成功完成。
SQL> select object_name, block_id, corrupt_type, marked_corrupt,
2 corrupt_description, repair_description
3 from repair_table;
OBJECT_NAME BLOCK_ID CORRUPT_TYPE MARKED_COR
-------------------- ---------- ------------ ----------
CORRUPT_DESCRIPTION
-------------------------------------------------------------------------------
REPAIR_DESCRIPTION
-------------------------------------------------------------------------------
TEST 19 6148 TRUE
mark block software corrupt
TEST 20 6148 TRUE
mark block software corrupt
TEST 23 6148 TRUE
mark block software corrupt
TEST 31 6148 TRUE
mark block software corrupt
通过运行dbms_repair.check_object,将坏块信息存放到了repair_table表中,其中有个字段marked_corrupt,用于标识该块是否被标识为坏块,当被标识为true时,即该块被标识为坏块。其中这一步跟oracle文档中的描述有点进入,根据oracle文档,当执行完dbms_repair.check_object时,并不会进行坏块标识,也就是marked_corrupt列的值应该为false,而只有当执行dbms_repair.fix_corrupt_blocks过程后才会进行坏块标识。
3)使用dbms_repair.fix_corrupt_blocks进行坏块标识
SQL> declare
2 fix_block_count int;
3 begin
4 fix_block_count := 0;
5 dbms_repair.fix_corrupt_blocks (
6 schema_name => 'SYS',
7 object_name => 'TEST',
8 object_type => dbms_repair.table_object,
9 repair_table_name => 'REPAIR_TABLE',
10 fix_count => fix_block_count);
11 dbms_output.put_line('fix blocks count: ' ||
12 to_char(fix_block_count));
13 end;
14 /
fix blocks count: 0
PL/SQL 过程已成功完成。
我们可以见到到fix blocks count=0,即在上一步进行check_object时已经进行了坏块标识了,这一步其实可以省略。(不过没有测试过!)
SQL> select count(*) from test;
select count(*) from test
*
第 1 行出现错误:
ORA-01578: ORACLE 数据块损坏 (文件号 7, 块号 19)
ORA-01110: 数据文件 7: 'G:ORACLEPRODUCT10.2.0ORADATAORA10GTEST01.DBF'
此时进行查询仍然报错,因为我们只是将坏块进行了标识,当进行全表扫描的时候,仍然会查询到坏块而报错。
4)使用dbms_repair.dump_orphan_keys过程来保存坏块的索引键值,然后再执行skip_corrupt_blocks过程之后,我们才能重建索引,不然重建索引时新的索引仍然会引用坏块。首先要建立ORPHAN_KEY_TABLE,此表就是用来存放坏块的索引键值。
SQL> declare
2 begin
3 dbms_repair.admin_tables
4 (table_name => 'ORPHAN_KEY_TABLE',
5 table_type => dbms_repair.orphan_table,
6 action => dbms_repair.create_action,
7 tablespace => 'USERS');
8 end;
9 /
PL/SQL 过程已成功完成。
然后执行过程dbms_repair.dump_orphan_keys将坏块键值存放到上面所创建的表中:
SQL> declare
2 orph_count int;
3 begin
4 orph_count:= 0;
5 dbms_repair.dump_orphan_keys (
6 schema_name => 'SYS',
7 object_name => 'ID_INX',--索引的名字
8 object_type => dbms_repair.index_object,
9 repair_table_name => 'REPAIR_TABLE',--从这个表中获得坏块的信息
10 orphan_table_name => 'ORPHAN_KEY_TABLE',
11 key_count => orph_count);
12 dbms_output.put_line('orphan-index entries: ' || to_char(orph_count));
13 end;
14 /
orphan-index entries: 491
PL/SQL 过程已成功完成。
SQL> declare
2 orph_count int;
3 begin
4 orph_count:= 0;
5 dbms_repair.dump_orphan_keys (
6 schema_name => 'SYS',
7 object_name => 'NAME_INX',
8 object_type => dbms_repair.index_object,
9 repair_table_name => 'REPAIR_TABLE',
10 orphan_table_name => 'ORPHAN_KEY_TABLE',
11 key_count => orph_count);
12 dbms_output.put_line('orphan-index entries: ' || to_char(orph_count));
13 end;
14 /
orphan-index entries: 491
PL/SQL 过程已成功完成。
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|