Oracle8i Administrator's Guide Release 8.1.5 A67772-01 |
|
Oracle provides different methods for detecting and correcting data block corruption. One method is to drop and re-create an object after the corruption is detected; however, this is not always possible or desirable. If data block corruption is limited to a subset of rows, another option is to rebuild the table by selecting all data except for the corrupt rows.
Yet another way to manage data block corruption is to use the DBMS_REPAIR package. You can use DBMS_REPAIR to detect and repair corrupt blocks in tables and indexes. Using this approach, you can address corruptions where possible, and also continue to use objects while you attempt to rebuild or repair them. DBMS_REPAIR uses the following approach to address corruptions:
Table 19-1 describes the procedures that make up the DBMS_REPAIR package.
Your first task, before using DBMS_REPAIR, should be the detection and reporting of corruptions. Reporting not only indicates 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 19-2 describes the different detection methodologies.
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 respectively.
Not only does check_object
report corruptions, but it also identifies any fixes that would occur if fix_corrupt_blocks
is subsequently run on the object. This information is made available by populating a repair table, which must first be created by the admin_tables
procedure.
After you run the check_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.
Typically, you use DB_VERIFY as an offline diagnostic utility when you encounter data corruption problems.
See Also: For more information about DB_VERIFY, see Oracle8i Utilities.
The ANALYZE TABLE...VALIDATE STRUCTURE statement validates the structure of the analyzed object. If Oracle successfully validates the structure, a message confirming its validation is returned to you. If Oracle encounters corruption in the structure of the object, an error message is returned to you. In this case, you would drop and re-create the object.
See Also: For more information about the ANALYZE statement, see the Oracle8i SQL Reference.
You can set block checking for instances via the DB_BLOCK_CHECKING parameter (the default value is TRUE); this checks data and index blocks whenever they are modified. DB_BLOCK_CHECKING is a dynamic parameter, modifiable by the ALTER SYSTEM SET statement.
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.
A first step is to answer the following questions:
To determine if there are corruptions and repair actions, execute the check_object
procedure, and query the repair table.
Assuming the data is available from another source, drop, re-create and re-populate the object. Another option is to issue the CREATE TABLE...AS SELECT statement from the corrupt table to create a new one.
You can ignore the corruption by excluding corrupt rows from select statements.
Perform media recovery.
You may not have access to rows in blocks marked corrupt. However, a block may be marked corrupt even though there are still rows that you can validly access.
Referential integrity constraints may be broken when blocks are marked corrupt. If this occurs, disable and re-enable the constraint; any inconsistencies will be reported. After fixing all issues, you should be able to successfully re-enable the constraint.
Logical corruption may occur when there are triggers defined on the table. For example, if rows are re-inserted, should insert triggers be fired or not? You can address these issues only if you understand triggers and their use in your installation.
Freelist blocks may be inaccessible. If a corrupt block is at the head or tail of a freelist, space management reinitializes the freelist. There then may be blocks that should be on a freelist, that aren't. You can address this by running the rebuild_freelists
procedure.
Indexes and tables may be out of sync. You can address this by first executing the dump_orphan_keys
procedure (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.
You can retrieve data from the index when a data block is marked corrupt. The dump_orphan_keys
procedures can help you retrieve this information. Of course, retrieving data in this manner depends on the amount of redundancy between the indexes and the table.
In this step DBMS_REPAIR makes the object usable by ignoring corruptions during table and index scans.
You make a corrupt object usable by establishing an environment that skips corruptions that remain outside the scope of DBMS_REPAIR's repair capabilities.
If corruptions involve a loss of data, such as a bad row in a data block, all such blocks are marked corrupt by the fix_corrupt_blocks
procedure. Then, you can run the skip_corrupt_blocks
procedure, which will skip blocks marked corrupt for the object. When skip is set, table and index scans skip all blocks marked corrupt. This applies to both media and software corrupt blocks.
If an index and table are out of sync, then a SET TRANSACTION READ ONLY transaction may be inconsistent in situations where one query probes only the index, and then a subsequent query probes both the index and the table. If the table block is marked corrupt, then the two queries will return different results, thereby breaking the rules of a read-only transaction. One way to approach this is to not skip corruptions when in a SET TRANSACTION READ ONLY transaction.
A similar issue occurs when selecting rows that are chained. Essentially, a query of the same row may or may not access the corruption--thereby giving different results.
After making an object usable, you can perform the following repair activities.
The dump_orphan_keys
procedure reports on index entries that point to rows in corrupt data blocks. All such index entries are inserted into an orphan key table that stores the key and rowid of the corruption.
After the index entry information has been retrieved, you can rebuild the index using the ALTER INDEX REBUILD ONLINE statement.
When a block marked "corrupt" is found at the head or tail of a freelist, the freelist is reinitialized and an error is returned. Although this takes the offending block off the freelist, it causes you to lose freelist access to all blocks that followed the corrupt block.
You can use the rebuild_freelists
procedure to reinitialize the freelists. The object is scanned, and if it is appropriate for a block to be on the freelist, it is added to the master freelist. Freelist groups are handled by meting out the blocks in an equitable fashion--a block at a time. Any blocks marked "corrupt" in the object are ignored during the rebuild.
DBMS_REPAIR procedures have the following limitations:
skip_corrupt_blocks
and rebuild_freelist
procedures, but not in the check_object
procedure.
dump_orphan_keys
procedure does not operate on bitmap indexes or function-based indexes.
dump_orphan_keys
procedure processes keys that are, at most, 3,950 bytes long.
This sections contains detailed descriptions of the DBMS_REPAIR procedures.
The check_object
procedure checks the specified objects, and populates the repair table with information about corruptions and repair directives. Validation consists of block checking all blocks in the object. You may optionally specify a range, partition name, or subpartition name when you wish to check a portion of an object.
procedure 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)
Use this procedure to fix the corrupt blocks in specified 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 marking the block software corrupt. When a repair is effected, the associated row in the repair table is updated with a fix timestamp.
procedure fix_corrupt_blocks( 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 boolean DEFAULT NULL, fix_count OUT binary_integer)
Reports on index entries that point to rows in corrupt data blocks. For each such index entry encountered, a row is inserted into the specified orphan table.
If the repair table is specified, then any corrupt blocks associated with the base table are handled in addition to all data blocks that are marked software corrupt. Otherwise, only blocks that are marked corrupt are handled.
This information may be useful for rebuilding lost rows in the table and for diagnostic purposes.
procedure dump_orphan_keys( schema_name IN varchar2, object_name IN varchar2, partition_name IN varchar2 DEFAULT NULL, object_type IN binary_integer DEFAULT INDEX_OBJECT, repair_table_name IN varchar2 DEFAULT 'REPAIR_TABLE', orphan_table_name IN varchar2 DEFAULT 'ORPHAN_KEY_TABLE', key_count OUT binary_integer)
Rebuilds the freelists for the specified object. All free blocks are placed on the master freelist. All other freelists are zeroed. If the object has multiple freelist groups, then the free blocks are distributed among all freelists, allocating to the different groups in round-robin fashion.
procedure rebuild_freelists( schema_name IN varchar2, object_name IN varchar2, partition_name IN varchar2 DEFAULT NULL, object_type IN binary_integer DEFAULT TABLE_OBJECT);
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.
procedure skip_corrupt_blocks( schema_name IN varchar2, object_name IN varchar2, partition_name IN varchar2 DEFAULT NULL, object_type IN binary_integer DEFAULT TABLE_OBJECT , flags IN boolean DEFAULT SKIP_FLAG);
Provides administrative functions for repair and orphan key tables.
procedure admin_tables( table_name IN varchar2, table_type IN binary_integer, action IN binary_integer, tablespace IN varchar2 DEFAULT NULL);
942 | repair table doesn't exist |
1418 | specified index doesn't exist |
24120 | invalid parameter |
24121 | can't specify CASCADE_FLAG and a block range |
24122 | invalid block range |
24124 | invalid action parameter specified |
24126 | CASCADE_FLAG specified and object is not a table |
24127 | tablespace specified and action is not CREATE_ACTION |
24128 | partition specified for non-partitioned object |
24129 | invalid orphan key table name - must have 'ORPHAN_' prefix |
24129 | specified repair table does not start with 'REPAIR_' prefix |
24131 | repair table has incorrect columns |
24132 | repair table name is too long |