< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Skip Headers

< /table>
Oracle® Database Administrator's Guide
10g Release 1 (10.1)

Part Number B10739-01

Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback
Go to previous page
Previous
Go to next page
Next
Vie w PDF

21 Detecting and Repairing Data Block Corruption

This chapter explains using the DBMS_REPAIR PL/SQL package to repair data block corruption in database schema objects. It contains the followi ng topics:

Options for R epairing Data Block Corruption

Oracle Database provides different methods for detecting and correcting data block corruption. On e method of correction is to drop and re-create an object after the corruption is detected. However, this is not always possible or d esirable. If data block corruption is limited to a subset of rows, another option is to rebuild the table by selecting all data excep t for the corrupt rows.

Yet another way to manage data block corruption is to use the DBMS_REPAIR package. You ca n use DBMS_REPAIR to detect and repair corrupt blocks in tables and indexes. Using this approach, you can address corrup tions where possible, and also continue to use objects while you attempt to rebuild or repair them.


Note:

Any corruption that involves the loss of data requir es analysis and understanding of how that data fits into the overall database system. DBMS_REPAIR is not a magic wand. Y ou must still determine whether the repair approach provided by this package is the appropriate tool for each specific corruption pro blem. Depending on the nature of the repair, you might lose data and logical inconsistencies can be introduced. Thus, you must weigh the gains and losses associated with using DBMS_REPAIR.

About the DBMS_REPAIR Pa ckage

This section describes the procedures contained in the DBMS_REPAIR package and notes some limitatio ns and restrictions on their use.


See A lso:

PL/SQL Packages and Ty pes Reference for more information on the syntax, restrictions, and exceptions for the DBMS_REPAIR procedures

< /a>

DBMS_REPAIR Procedures

The following table lists th e procedures included in the DBMS_REPAIR package.

< td align="left" id="r8c1-t5" headers="r1c1-t5">ADMIN_TABLES
Procedure Name Description
C HECK_OBJECT Detects and reports corruptions in a table or index
FIX_CORRUPT _BLOCKS Marks blocks (that were previously identified by the CHECK_OBJEC T procedure) as software corrupt
DUMP_ORPHAN_KEYS Reports index entr ies (into an orphan key table) that point to rows in corrupt data blocks
REBUILD_FREELISTS Rebuilds the free lists of the object
SEGMENT_FIX_STATUS Pr ovides the capability to fix the corrupted state of a bitmap entry when segment space management is AUTO
SKIP_CORRUPT _BLOCKS When used, ignores blocks marked corrupt during table and index scans. If not used, you get error ORA-1578 when encountering blocks marked corrupt.
Provides administrative functions (create, drop, purge) for repair or orphan key tables.

Not e: These tables are always created in the SYS schema.


These procedures are further described, with examples of their use, in "DBMS_REPAIR Examp les".

Limitations and Restrictions

DBMS_REP AIR procedures have the following limitations:

  • Tables with LOBs, nested tables, and varrays are supported, but the out of line columns are ignored.

  • Clusters are supported in the SKIP _CORRUPT_BLOCKS and REBUILD_FREELISTS procedures, but not in the CHECK_OBJECT procedure.

  • Index-organized tables and LOB indexes are not supported.

  • The DUMP_ ORPHAN_KEYS procedure does not operate on bitmap indexes or function-based indexes.

  • The DUM P_ORPHAN_KEYS procedure processes keys that are, at most, 3,950 bytes long.

Using the DBMS_REPAIR Package

The following approach is recommended when considering DBMS_REPAIR for addressing data block corruption:

The se tasks are discussed in succeeding sections.

Task 1: Detect and Report Corruptions

Your first task, before using DBMS_REPAIR, should be the detection and reporting of corruptions. Reporting not only ind icates what is wrong with a block, but also identifies the associated repair directive. You have several options, in addition to DBMS_REPAIR, for detecting corruptions. Table 21-1 describes the different detection methodologies.< /p>

Table 21-1 Comparison of Corruption Detection Methods

< tr align="left" valign="top">
Detection Method Description
DBMS_REPAIR Performs block checking for a specified table, partition, or index. Populates a repair table with results.
DB_VE RIFY External command-line utility that performs block checking on an offline database.
ANALYZE Used with the VALIDATE STRUCTURE option, ver ifies the integrity of the structure of an index, table, or cluster; checks or verifies that your tables and indexes are in sync.
DB_BLOCK_CHECKING Performed when the initialization parameter DB_BLOCK_C HECKING=TRUE. Identifies corrupt blocks before they actually are marked corrupt. Checks are performed when changes are made to a block.

DBMS_REPAIR: Using the CHECK_OBJECT and ADMIN_TABLES Procedure s

The CHECK_OBJECT procedure checks and reports block corruptions for a specified object. Similar to the ANALYZE ... VALIDATE STRUCTURE statement for indexes and tables, block checking is performed for index and data blocks.< /p>

Not only does CHECK_OBJECT report corruptions, but it also identifies any fixes that would occur if FIX_COR RUPT_BLOCKS is subsequently run on the object. This information is made available by populating a repair table, which must fir st be created by the ADMIN_TABLES procedure.

After you run the CHE CK_OBJECT procedure, a simple query on the repair table shows the corruptions and repair directives for the object. With this information, you can assess how best to address the problems reported.

ANALYZE: Corruption Reporting

T he ANALYZE TABLE ... VALIDATE STRUCTURE statement validates the structure of the analyzed object. If the database succes sfully validates the structure, a message confirming its validation is returned to you. If the database encounters corruption in the structure of the object, an error message is returned to you. In this case, drop and re-create the object.

< div class="inftblnotealso">

See Also:

Oracle Database SQL Reference for more information about the < code>ANALYZE statement

Task 2: Evaluate the Costs and Benefits of Using DBMS_REPAIR

Before using DBMS_REPAIR you must weigh the benefits of its use in relation to the liabilities. You should also examine other options available for addressing corrupt objects. Begin by answering th e following questions:

  • What is the extent of the corruption?

    To determine if there are corruption s and repair actions, execute the CHECK_OBJECT procedure, and query the repair table.

  • What other options are available for addressing block corruptions? Consider the following:

  • If the data is available from another source, then drop, re-create, and repopulate the object.

  • Issue the CREATE TABLE ... AS SELECT statement from the corrupt table to create a new one.

  • Ignore the corruption by excluding corrupt rows from select statements.

  • Perform me dia recovery.

  • What logical corruptions or side effects are introduced when you use DBMS_ REPAIR to make an object usable? Can these be addressed? What is the effort required to do so?

    It is possible that you do not have access to rows in blocks marked corrupt. However, a block could be marked corrupt even though there are still rows that y ou can validly access.

    It is also possible that referential integrity constraints are broken when blocks are marked corrupt. I f this occurs, disable and reenable the constraint; any inconsistencies are reported. After fixing all problems, you should be able t o successfully reenable the constraint.

    Logical corruption can occur when there are triggers defined on the table. For example , if rows are reinserted, should insert triggers be fired or not? You can address these issues only if you understand triggers and th eir use in your installation.

    Free list blocks can become inaccessible. If a corrupt block is at the head or tail of a free li st, space management reinitializes the free list. There then can be blocks that should be on a free list, but are not. You can addres s this by running the REBUILD_FREELISTS procedure.

    Indexes and tables ar e out of sync. You can address this by first executing the DUMP_ORPHAN_KEYS pro cedure (to obtain information from the keys that might be useful in rebuilding corrupted data). Then issue the ALTER INDEX ... REBUILD ONLINE statement to get the table and its indexes back in sync.

  • If repair involves loss o f data, can this data be retrieved?

    You can retrieve data from the index when a data block is marked corrupt. The DUMP_ORPHAN_KEYS procedure can help you retrieve this information. Of course, retrieving da ta in this manner depends on the amount of redundancy between the indexes and the table.

  • < a id="i1006347" name="i1006347">

    Task 3: Make Objects Usable

    In this task DBMS_REPAIR makes the object usable by ignoring corruptions during table and index scans.

    Corruption Repair: Using the FIX_CORRUPT_BLOCKS and SKIP_CORRUPT_BLOCKS Procedures< /font>

    You make a corrupt object usable by establishing an environment that skips corruptions that remain outside the scope o f DBMS_REPAIR capabilities.

    If corruptions involve a loss of data, such as a bad row in a data block, all such bl ocks are marked corrupt by the FIX_CORRUPT_BLOCKS procedure. Then, you can run the SKIP_CORRUPT_BLOCKS procedure, which skips blocks marked corrupt for the ob ject. When skip is set, table and index scans skip all blocks marked corrupt. This applies to both media and software corrupt blocks.

    Implications when Skipping Corrupt Blocks

    If an index and table are out of sync, then a SET TRANSACTION READ ONLY transaction can be inconsistent in situations where one query probes only the index, and then a sub sequent query probes both the index and the table. If the table block is marked corrupt, then the two queries return different result s, thereby breaking the rules of a read-only transaction. One way to approach this is to not skip corruptions when in a SET TRA NSACTION READ ONLY transaction.

    A similar issue occurs when selecting rows that are chained. Essentially, a query of th e same row may or may not access the corruption, thereby producing different results.

    Task 4: Repair Corruptions and Rebuild Lost Data

    After making an object usable, you can perform the following repair activities.

    Recover Data Using the DUMP_ORPHAN_KEYS Procedures

    The DUMP_ORPHAN_KEYS procedure reports on index entries that point to rows in corrupt data blo cks. All such index entries are inserted into an orphan key table that stores the key and rowid of the corruption.

    After the i ndex entry information has been retrieved, you can rebuild the index using the ALTER INDEX ... REBUILD ONLINE statement.

    Repair Free Lists Using the REBUILD_FREELISTS Procedure

    Use this procedure if free space in s egments is being managed using free lists (SEGMENT SPACE MANAGEMENT MANUAL).

    When a block marked "corrupt" is fou nd at the head or tail of a free list, the free list is reinitialized and an error is returned. Although this takes the offending blo ck off the free list, it causes you to lose free list access to all blocks that followed the corrupt block.

    You can use the REBUILD_FREELISTS procedure to reinitialize the free lists. The object is scanned , and if it is appropriate for a block to be on the free list, it is added to the master free list. Free list groups are handled by d istributing blocks in an equitable fashion, one block at a time. Any blocks marked "corrupt" in the object are ignored during the reb uild.

    Fix Segment Bitmaps Using the SEGMENT_FIX_STATUS Procedure

    Use this procedure if free sp ace in segments is being managed using bitmaps (SEGMENT SPACE MANAGEMENT AUTO).

    This procedure either recalculate s the state of a bitmap entry based on the current contents of the corresponding block, or you can specify that a bitmap entry be set to a specific value. Usually, the state is recalculated correctly and there is no need to force a setting.

    DBMS_REPAIR Examples

    In this section, examples are presented reflecting the use of the DBMS_REPAIR procedures.

    Using ADMIN_TABLES to Build a Repair Ta ble or Orphan Key Table

    A repair table provides information about what corruptions were found by the CHECK_OBJEC T procedure and how these will be addressed if the FIX_CORRUPT_BLOCKS procedure is run. Further, it is used to dr ive the execution of the FIX_CORRUPT_BLOCKS procedure.

    An orphan key table is used when the DUMP_ORPHAN_KEY S procedure is executed and it discovers index entries that point to corrupt rows. The DUMP_ORPHAN_KEYS procedure populates the orphan key table by logging its activity and providing the index information in a usable manner.

    The ADMI N_TABLE procedure is used to create, purge, or drop a repair table or an orphan key table.

    Creating a Repair Table

    The following example creates a repair table for the users tablespace.

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

    For each repair or orphan key table, a view is also created that eliminates any rows that pertain to objects that no l onger exist. The name of the view corresponds to the name of the repair or orphan key table, but is prefixed by DBA_ (fo r example DBA_REPAIR_TABLE or DBA_ORPHAN_KEY_TABLE).

    The following query describes the repair table created in the previous example.

    DESC REPAIR_TABLE
    
     Name                         Null?    Type
     ------
    ---------------------- -------- --------------
     OBJECT_ID                    NOT NULL NUMBER
     TABLESPACE_ID                NOT NULL N
    UMBER
     RELATIVE_FILE_ID             NOT NULL NUMBER
     BLOCK_ID                     NOT NULL NUMBER
     CORRUPT_TYPE                 NOT N
    ULL 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
     FIX_TIMESTAMP                         DATE
     REFORMAT_TIMESTAMP                    DATE
    

    Creating an Orphan Key Table

    T his example illustrates the creation of an orphan key table for the users tablespace.

    BEGI
    N
    DBMS_REPAIR.ADMIN_TABLES (
         TABLE_NAME => 'ORPHAN_KEY_TABLE',
         TABLE_TYPE => dbms_repair.orphan_table,
         ACTION
      => dbms_repair.create_action,
         TABLESPACE => 'USERS');
    END;
    /
    
    

    The orphan key table is described in the follow ing query:

    DESC ORPHAN_KEY_TABLE
    
     Name                         Null?    Type
     ------------------------
    ---- -------- -----------------
     SCHEMA_NAME                  NOT NULL VARCHAR2(30)
     INDEX_NAME                   NOT NULL VARCHAR2(3
    0)
     IPART_NAME                            VARCHAR2(30)
     INDEX_ID                     NOT NULL NUMBER
     TABLE_NAME                   NO
    T NULL VARCHAR2(30)
     PART_NAME                             VARCHAR2(30)
     TABLE_ID                     NOT NULL NUMBER
     KEYROWID
                   NOT NULL ROWID
     KEY                          NOT NULL ROWID
     DUMP_TIMESTAMP               NOT NULL DATE
    

    Using the CHECK_OBJECT Procedure to Detect Corrupt ion

    The CHECK_OBJECT procedure checks the specified objects, and populates the repair table with information about corruptions and repair directives. You can optionally specify a range, partition n ame, or subpartition name when you would like to check a portion of an object.

    Validation consists of checking all blocks in t he object that have not previously been marked corrupt. For each block, the transaction and data layer portions are checked for self consistency. During CHECK_OBJECT, if a block is encountered that has a corrupt buffer cache header, then that block is s kipped.

    Here is an example of executing the CHECK_OBJECT procedure for the scott.dept table.

    SET SERVEROUTPUT ON DECLARE num_corrupt INT; BEGIN num_corrupt := 0; DBMS_REPAIR.CHECK_OBJECT ( SCHEMA_NA ME => 'SCOTT', OBJECT_NAME => 'DEPT', REPAIR_TABLE_NAME => 'REPAIR_TABLE', CORRUPT_COUNT => num_corrupt); DBMS_OUTPUT.PUT_LINE('number corrupt: ' || TO_CHAR (num_corrupt)); END; /

    SQL*Plus outputs the following line, indicatin g one corruption:

    number corrupt: 1
    
    

    Querying the repair table produces information describi ng the corruption and suggesting a repair action.

    SELECT OBJECT_NAME, BLOCK_ID, CORRUPT_TYPE, MARKED_CO
    RRUPT,
           CORRUPT_DESCRIPTION, REPAIR_DESCRIPTION
         FROM REPAIR_TABLE;
    
    OBJECT_NAME                      BLOCK_ID CORRUPT_TYPE
     MARKED_COR
    ------------------------------ ---------- ------------ ----------
    CORRUPT_DESCRIPTION
    -----------------------------------
    -------------------------------------------
    REPAIR_DESCRIPTION
    ----------------------------------------------------------------------
    --------
    DEPT                                    3            1 FALSE
    kdbchk: row locked by non-existent transaction
            table=0
      slot=0
            lockid=32   ktbbhitc=1
    mark block software corrupt
    
    

    At this point, the corrupted block has not yet been m arked corrupt, so this is the time to extract any meaningful data. After the block is marked corrupt, the entire block must be skippe d.

    Fixing Corrupt Blocks with the FIX_CORRUPT_BLOCKS Procedure< /h3>

    Use the FIX_CORRUPT_BLOCKS procedure to fix the corrupt blocks in speci fied objects based on information in the repair table that was previously generated by the CHECK_OBJECT procedure. Prior to effecting any change to a block, the block is checked to ensure the block is still corrupt. Corrupt blocks are repaired by markin g the block software corrupt. When a repair is performed, the associated row in the repair table is updated with a fix timestamp.

    This example fixes the corrupt block in table scott.dept that was reported by the CHECK_OBJECT procedur e.

    SET SERVEROUTPUT ON
    DECLARE num_fix INT;
    BEGIN 
    num_fix := 0;
    DBMS_REPAIR.FIX_CORRUPT_BLOCKS (
    SCHEMA_NAME => 'SCOTT',
         OBJECT_NAME=> 'DEPT',
         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;
    /
    
    SQL*Plus outputs the f
    ollowing line:
    
    num fix: 1
    
    

    To following query confirms that the repair was done.

    SELECT OBJ
    ECT_NAME, BLOCK_ID, MARKED_CORRUPT
         FROM REPAIR_TABLE;
    
    OBJECT_NAME                      BLOCK_ID MARKED_COR
    --------------------
    ---------- ---------- ----------
    DEPT                                    3 TRUE
    

    Finding Index Entries Pointing into Corrupt Data Blocks: DUMP_ORPHAN_KEYS

    The DUMP_ORPHAN_KEYS procedure reports on index entries that point to rows in corrupt data blocks. For each s uch index entry encountered, a row is inserted into the specified orphan key table. The orphan key table must have been previously cr eated.

    This information can be useful for rebuilding lost rows in the table and for diagnostic purposes.


    Note:

    This should be run for every index assoc iated with a table identified in the repair table.

    In thi s example, pk_dept is an index on the scott.dept table. It is scanned to determine if there are any index e ntries pointing to rows in the corrupt data block.

    SET SERVEROUTPUT ON
    DECLARE num_orphans INT;
    BEGIN
    n
    um_orphans := 0;
    DBMS_REPAIR.DUMP_ORPHAN_KEYS (
         SCHEMA_NAME => 'SCOTT',
         OBJECT_NAME => 'PK_DEPT',
         OBJECT_TYPE =&
    gt; dbms_repair.index_object,
         REPAIR_TABLE_NAME => 'REPAIR_TABLE',
         ORPHAN_TABLE_NAME=> 'ORPHAN_KEY_TABLE',
         KEY_C
    OUNT => num_orphans);
    DBMS_OUTPUT.PUT_LINE('orphan key count: ' || TO_CHAR(num_orphans));
    END;
    /
    
    

    The following line is output, indicating there are three orphan keys:

    orphan key count: 3
    
    

    Index entries in the o rphan key table implies that the index should be rebuilt. This guarantees that a table probe and an index probe return the same resul t set.

    Rebuilding Free Lists Using the REBUILD_FREELISTS Procedure

    The REBUILD_FREELISTS procedure rebuilds the free lists for the spe cified object. All free blocks are placed on the master free list. All other free lists are zeroed. If the object has multiple free l ist groups, then the free blocks are distributed among all free lists, allocating to the different groups in round-robin fashion.

    This example rebuilds the free lists for the table scott.dept.

    BEGIN
    DBMS_REPAIR.REBUI
    LD_FREELISTS (
         SCHEMA_NAME => 'SCOTT',
         OBJECT_NAME => 'DEPT',
         OBJECT_TYPE => dbms_repair.table_object);
    END;
    /
    

    Enabling or Disabling the Skipping of Corrupt Blocks: SKIP_CORRU PT_BLOCKS

    The SKIP_CORRUPT_BLOCKS procedure enables or disables the skipping of corrupt blocks during index and table scans of the specified object. When the object is a table, skip applies to the table and its indexes. When the object is a cluster, it applies to all of the tables in the cluster, and their respective indexes.

    The following example enables the skipping of software corrupt blocks for the scott.dept table:

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

    Querying scott's tables using the DBA_TABLES view shows that SKIP_CORRUPT is enabled for table scott.dept.

    SELECT OWNER, TABLE_NAME, SKIP_CORRUPT FROM DBA_TABLES
        WHERE OWNER = 'SCOTT';
    
    OWNER                          TABLE_
    NAME                     SKIP_COR
    ------------------------------ ------------------------------ --------
    SCOTT
       ACCOUNT                        DISABLED
    SCOTT                          BONUS                          DISABLED
    SCOTT
                DEPT                           ENABLED
    SCOTT                          DOCINDEX                       DISABLED
    SCOTT
                        EMP                            DISABLED
    SCOTT                          RECEIPT                        DISABLED
    SC
    OTT                          SALGRADE                       DISABLED
    SCOTT                          SCOTT_EMP                      DI
    SABLED
    SCOTT                          SYS_IOT_OVER_12255             DISABLED
    SCOTT                          WORK_AREA
           DISABLED
    
    10 rows selected.