|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Advanced Oracle Utilities: The Definitive Reference by Rampant TechPress is written by top Oracle database experts (Bert Scalzo, Donald Burleson, and Steve Callan). The following is an excerpt from the book.
Dbms_repair
is
a utility that can detect and repair block corruption within Oracle.
It is provided by Oracle as part of the standard database
installation.
Two
tables must first be created under the SYS schema before the dbms_repair
utility can be used.
Fortunately, a procedure in the package itself (admin_tables)
creates these tables and eliminates the need to hunt for a script in
$ORACLE_HOME/rdbms/admin. dbms_repair.ADMIN_TABLES (
table_name
IN VARCHAR2,
table_type
IN
BINARY_INTEGER,
action
IN
BINARY_INTEGER,
tablespace
IN VARCHAR2
DEFAULT NULL);
The
following command will be used to create the two tables needed.
The command will be executed twice with different parameters, once for
the
repair table and once for the
orphan table.
begin
dbms_repair.admin_tables(
table_name => 'REPAIR_TEST',
table_type => dbms_repair.repair_table,
action
=> dbms_repair.create_action,
tablespace => 'SCOTTWORK'
); end; begin
dbms_repair.admin_tables(
table_name => 'ORPHAN_TEST',
table_type => dbms_repair.orphan_table,
action
=> dbms_repair.create_action,
tablespace => 'SCOTTWORK'
); end;
The
two tables are now created.
A describe of the two tables reveals the following: SQL> desc repair_test; Name
Null?
Type -----------------------------------------
-------- --------------- OBJECT_ID
NOT NULL NUMBER TABLESPACE_ID
NOT NULL NUMBER RELATIVE_ BLOCK_ID
NOT NULL NUMBER CORRUPT_TYPE
NOT NULL NUMBER SCHEMA_NAME
NOT NULL VARCHAR2(30) OBJECT_NAME
NOT NULL VARCHAR2(30) BASEOBJECT_NAME
VARCHAR2(30) PARTITION_NAME
VARCHAR2(30) CORRUPT_DESCRIPTION
VARCHAR2(2000) REPAIR_DESCRIPTION
VARCHAR2(200) MARKED_CORRUPT
NOT NULL VARCHAR2(10) CHECK_TIMESTAMP
NOT NULL DATE REFORMAT_TIMESTAMP
DATE SQL> desc orphan_test Name
Null?
Type -----------------------------------------
-------- --------------- SCHEMA_NAME
NOT NULL VARCHAR2(30) INDEX_NAME
NOT NULL VARCHAR2(30) IPART_NAME
VARCHAR2(30) INDEX_ID
NOT NULL NUMBER TABLE_NAME
NOT NULL VARCHAR2(30) PART_NAME
VARCHAR2(30) TABLE_ID
NOT NULL NUMBER KEYROWID
NOT NULL ROWID DUMP_TIMESTAMP
NOT NULL DATE
Repair tables will contain those objects that have corrupted blocks.
Orphan tables, on the other hand, are used to contain indexes that
point to corrupted data
The
dbms_repair utility provides a mechanism to search for corrupt database blocks.
Below is the syntax for the
check_objects procedure. Note that the only OUT
parameter is the
corrupt_count. dbms_repair.CHECK_OBJECT (
schema_name
IN VARCHAR2,
object_name
IN VARCHAR2,
partition_name
IN VARCHAR2
DEFAULT NULL,
object_type
IN BINARY_INTEGER
DEFAULT TABLE_OBJECT,
repair_table_name IN
VARCHAR2
DEFAULT 'REPAIR_TABLE',
flags
IN BINARY_INTEGER
DEFAULT NULL,
relative_fno
IN BINARY_INTEGER
DEFAULT NULL,
block_start
IN BINARY_INTEGER
DEFAULT NULL,
block_end
IN BINARY_INTEGER
DEFAULT NULL,
corrupt_count
OUT BINARY_INTEGER);
The
code below will check the
scott.employee table for corruption and report the number of
corrupted blocks.
dbms_repair.sql set serveroutput on declare corr_count binary_integer; begin corr_count := 0; dbms_repair.CHECK_OBJECT (
schema_name
=> 'SCOTT',
object_name
=> 'EMPLOYEE',
partition_name
=> null,
object_type
=> dbms_repair.table_object,
repair_table_name => 'REPAIR_TEST',
flags
=> null,
relative_fno
=> null,
block_start
=> null,
block_end
=> null,
corrupt_count
=> corr_count
); dbms_output.put_line(to_char(corr_count));
end; / # Corrupt Blocks =0 PL/SQL procedure successfully completed.
Once executed, the table
repair_test can be queried in order to find more about corrupt
blocks. In this case, no rows
exist in the table. The repair
table is only populated if the
check_object procedure did indeed find corrupt blocks, so no
rows in this table is good news!
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright © 1996 - 2011 by
Burleson Enterprises. All rights reserved.
Oracle® is the registered trademark
of Oracle Corporation. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||