You can resolve inconsistencies with the REPAIR utility. However, using REPAIR is not recommended unless the inconsistency is limited to a small number of data or index pages.
About this task
Db2 does not provide a mechanism to automatically inform users about data that is physically inconsistent or damaged. When you use SQL to access data that is physically damaged, Db2 issues messages to indicate that data is not available due to a physical inconsistency.
However, Db2 includes several utilities that can help you identify data that is physically inconsistent before you try to access it. These utilities are:
- CHECK DATA
- CHECK INDEX
- CHECK LOB
- COPY with the CHECKPAGE option
- DSN1COPY with the CHECK option
Attention: If you decide to use this method to resolve data inconsistencies, use extreme care. Use of the REPAIR utility to correct inconsistencies requires in-depth knowledge of Db2 data structures. Incorrect use of the REPAIR utility can cause further corruption and loss of data. Read this topic carefully because it contains information that is important to the successful resolution of the inconsistencies.
Recommendation: Avoid using this procedure if you are experiencing extensive data inconsistency because it is more time-consuming and complex (and therefore prone to error) than recovering to a point in time or re-creating the table spaces. If possible, use those alternative procedures instead.
Restrictions:
- Although the DSN1LOGP utility can identify page sets that contain inconsistencies, this utility cannot identify the specific data modifications that are involved in the inconsistencies within a given page set.
- Any pages that are on the logical page list (perhaps caused by this restart) cannot be accessed by using the REPAIR utility.
Procedure
To use the REPAIR utility to resolve the inconsistency:
- Issue the following command to start Db2 and allow access to data:
START DATABASE (dbase) SPACENAM (space) ACCESS(FORCE)
In this command, space identifies the table space that is involved.
- If any system data is inconsistent, use the REPAIR utility to resolve those inconsistencies.
Db2 system data (such as data that is in the catalog and directory) exists in interrelated tables and table spaces. Data in Db2 system databases cannot be modified with SQL, so use of the REPAIR utility is necessary to resolve the inconsistencies that are identified.
- Determine if you have any structural violations in data pages.
Db2 stores data in data pages. The structure of data in a data page must conform to a set of rules for Db2 to be able to process the data accurately. Using a conditional restart process does not cause violations to this set of rules; but, if violations existed prior to conditional restart, they continue to exist after conditional restart.
- Use the DSN1COPY utility with the CHECK option to identify any violations that you detected in the previous step, and then resolve the problems, possibly by recovering or rebuilding the object or by dropping and re-creating it.
- Examine the various types of pointers that Db2 uses to access data (indexes and hashes), and identify inconsistencies that need to be manually corrected.
Hash pointers exist in the
Db2 directory database.
Db2 uses these pointers to access data. During a conditional restart, data pages might be modified without update of the corresponding pointers. When this occurs, one of the following actions might occur:
- If a pointer addresses data that is nonexistent or incorrect, Db2 abends the request. If SQL is used to access the data, a message that identifies the condition, and the page in question is issued.
- If data exists but no pointer addresses it, that data is virtually invisible to all functions that attempt to access it by using the damaged hash pointer. The data might, however, be visible and accessible by some functions, such as SQL functions that use another pointer that was not damaged. This situation can result in inconsistencies.
If a row that contains a varying-length field is updated, it can increase in size. If the page in which the row is stored does not contain enough available space to store the additional data, the row is placed in another data page, and a pointer to the new data page is stored in the original data page. After a conditional restart, one of the following conditions might exist.
- The row of data exists, but the pointer to that row does not exist. In this case, the row is invisible, and the data cannot be accessed.
- The pointer to the row exists, but the row itself no longer exists. Db2 abends the requester when any operation (for instance, a SELECT) attempts to access the data. If termination occurs, one or more messages are issued to identify the condition and the page that contains the pointer.
- Use the REPAIR utility to resolve any inconsistencies that you detected in the previous step.
- Reset the log RBA in every data and index page set that are to be corrected with this procedure by using the DSN1COPY RESET option.
This step is necessary for the following reason. If the log was truncated, changing data by using the REPAIR utility can cause problems. Each data and index page contains the log RBA of the last recovery log record that was applied against the page. Db2 does not allow modification of a page that contains a log RBA that is higher than the current end of the log.
- When all known inconsistencies have been resolved, take full image copies of all modified table spaces, in order to use the RECOVER utility to recover from any future problems.
This last step is imperative.