暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

DBMS_REPAIR EXAMPLE SCRIPT WITH PARTITION

黑獭 2024-07-05
101

DBMS_REPAIR EXAMPLE SCRIPT WITH PARTITION


DBMS_REPAIR EXAMPLE SCRIPT WITH PARTITION (Doc ID 1436664.1)
DBMS_REPAIR SCRIPT (Doc ID 556733.1)





Run sqlplus with SYS user

1. Run sqlplus. Example:

sqlplus '/ as sysdba'

Instructions
run the script from sqlplus

Script
2. Use the DBMS_REPAIR (CHECK_OBJECT/FIX_CORRUPT_BLOCKS/SKIP_CORRUPT_BLOCKS ) to find, mark and skip corrupted blocks.

REM Used to create the REPAIR_TABLE from 10g and Above SYSAUX can be used as tablespace

BEGIN
DBMS_REPAIR.ADMIN_TABLES (
TABLE_NAME => 'REPAIR_TABLE',
TABLE_TYPE => dbms_repair.repair_table,
ACTION => dbms_repair.create_action,
TABLESPACE => '&TABLESPACE_NAME');
END;

REM Used to identified the corrupted blocks for Owner.Table (partition_name):

set serveroutput on
DECLARE num_corrupt INT;
BEGIN
num_corrupt := 0;
DBMS_REPAIR.CHECK_OBJECT (
SCHEMA_NAME => '&OWNER',
OBJECT_NAME => '&TABLE',
partition_name => '&PARTITION_NAME',
REPAIR_TABLE_NAME => 'REPAIR_TABLE',
corrupt_count => num_corrupt);
DBMS_OUTPUT.PUT_LINE('number corrupt: ' || TO_CHAR (num_corrupt));
END;

REM Used to list corrupted blocks (Optional).

Select * from REPAIR_TABLE;

REM Used to mark the identified blocks as corrupted blocks:

DECLARE num_fix INT;
BEGIN
num_fix := 0;
DBMS_REPAIR.FIX_CORRUPT_BLOCKS (
SCHEMA_NAME => '&OWNER',
OBJECT_NAME=> '&TABLE',
partition_name => '&PARTITION_NAME',
OBJECT_TYPE => dbms_repair.table_object,
REPAIR_TABLE_NAME => 'REPAIR_TABLE',
FIX_COUNT=> num_fix);
DBMS_OUTPUT.PUT_LINE('num fix: ' || to_char(num_fix));
END;

REM Used to skip the corrupted blocks:

BEGIN
DBMS_REPAIR.SKIP_CORRUPT_BLOCKS (
SCHEMA_NAME => '&OWNER',
OBJECT_NAME => '&TABLE',
OBJECT_TYPE => dbms_repair.table_object,
FLAGS => dbms_repair.skip_flag);
END;
/

3. Saving data on the table by skipping the corrupted blocks.

Export/Truncate/Import table/partition==> &OWNER.&TABLE_NAME partition==> &PARTITION_NAME

To export Table/Partition, run (From OS Prompt)

exp userid=<owner>/<password> file=<export_file.dmp> tables=<TABLE_NAME>:<PARTITION_NAME> rows=y log=<export_file.log>
To truncate the Table/Partition, run from sqlplus:

ALTER TABLE &OWNER.&TABLE_NAME
TRUNCATE PARTITION &PARTITION_NAME update global indexes;
To import Table/Partition, run (From OS Prompt)

imp userid=<owner>/<password> file=<export_file.dmp> tables=<TABLE_NAME>:<PARTITION_NAME> rows=y ignore=y log=<import_file.log>
4. Rebuild any index which might become unusable after the truncate is executed and no maintained by
update global indexes option.

SQL> select owner, index_name, index_type, status, table_name , table_owner from dba_indexes
Where table_owner = '&OWNER' and
Table_name = '&TABLE_NAME' and status = 'UNUSABLE';
To rebuild the index, run:

SQL> alter index &OWNER.&INDEX_NAME rebuild;
5. Remove the skip flag, run from sqlplus

execute DBMS_REPAIR.SKIP_CORRUPT_BLOCKS(SCHEMA_NAME=>'&OWNER',OBJECT_NAME=>'&TABLE_NAME',flags=>sys.dbms_repair.NOSKIP_FLAG);













「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论