The following approach is recommended when considering
DBMS_REPAIR for addressing data block corruption:
The first task is the detection and reporting of corruptions. Reporting not only indicates what is wrong with a block, but also identifies the associated repair directive. There are several ways to detect corruptions. Table 23-1 describes the different detection methodologies.
Performs block checking for a specified table, partition, or index. It populates a repair table with results.
Performs block checking on an offline database
Used with 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.
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
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 reported problems.
DB_VERIFY as an offline diagnostic utility when you encounter data corruption.
See Also:Oracle Database Utilities for more information about
ANALYZE TABLE...VALIDATE STRUCTURE statement validates the structure of the analyzed object. If the database encounters corruption in the structure of the object, then an error message is returned. In this case, drop and re-create the object.
You can use the
CASCADE clause of the
ANALYZE TABLE statement to check the structure of the table and all of its indexes in one operation. Because this operation can consume significant resources, there is a FAST option that performs a lightweight check. See "Validating Tables, Indexes, Clusters, and Materialized Views" for details.
Oracle Database SQL Language Reference for more information about the
You can enable database block checking by setting the
DB_BLOCK_CHECKING initialization parameter to
TRUE. This checks data and index blocks for internal consistency whenever they are modified.
DB_BLOCK_CHECKING is a dynamic parameter, modifiable by the
ALTER SYSTEM SET statement. Block checking is always enabled for the system tablespace.
See Also:Oracle Database Reference for more information about the
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 the following questions:
What is the extent of the corruption?
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.
CREATE TABLE...AS SELECT statement from the corrupt table to create a new one.
Ignore the corruption by excluding corrupt rows from
Perform media recovery.
It is possible that you do not have access to rows in blocks marked corrupt. However, a block can be marked corrupt even if there are rows that you can validly access.
It is also possible that referential integrity constraints are broken when blocks are marked corrupt. If this occurs, then disable and reenable the constraint; any inconsistencies are reported. After fixing all problems, you should be able to 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 their use in your installation.
If indexes and tables are not synchronized, then execute 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 synchronize the table with its indexes.
If repair involves loss of data, can this data be retrieved?
DBMS_REPAIR makes the object usable by ignoring corruptions during table and index scans.
You can make a corrupt object usable by establishing an environment that skips corruptions that remain outside the scope of
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 skips blocks that are marked as corrupt. When the
SKIP_FLAG parameter in the procedure 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 not synchronized, then a
SET TRANSACTION READ ONLY transaction can be inconsistent in situations where one query probes only the index, and a subsequent query probes both the index and the table. If the table block is marked corrupt, then the two queries return different results, thereby breaking the rules of a read-only transaction. One way to approach this is not to skip corruptions in a
SET TRANSACTION READ ONLY transaction.
A similar issue occurs when selecting rows that are chained. A query of the same row may or may not access the corruption, producing different results.
After making an object usable, perform the following repair activities.
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.
Use this procedure if free space in segments is being managed by using bitmaps (
SEGMENT SPACE MANAGEMENT AUTO).
This procedure recalculates the state of a bitmap entry based on the current contents of the corresponding block. Alternatively, 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.