An index that does not match its table is worse than no index: SQL can return the wrong rows or miss rows that exist. The CHECK INDEX online utility on DB2 for z/OS compares index keys with the data, reports mismatches, and is the standard health check after point-in-time recovery — and before CHECK DATA DELETE YES.
CHECK INDEX tests whether indexes are consistent with the data they index and issues warning messages when it finds an inconsistency. Consistency means:
The utility does not rewrite the index. If keys are missing or extra, the usual repair is REBUILD INDEX (or RECOVER INDEX from a good copy plus log). REORG INDEX will not magically invent missing keys from the table.
1234567891011//CIX EXEC PGM=DSNUTILB,PARM='DB2A,CIXEMP' //STEPLIB DD DISP=SHR,DSN=DSN.SDSNLOAD //SYSPRINT DD SYSOUT=* //UTPRINT DD SYSOUT=* //SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(20,20)) //SORTOUT DD UNIT=SYSDA,SPACE=(CYL,(20,20)) //SYSIN DD * CHECK INDEX (HR.IXEMPNO, HR.IXDEPT) SHRLEVEL REFERENCE SORTDEVT SYSDA /*
Other shapes: CHECK INDEX (ALL) TABLESPACE db.ts, INDEXSPACE db.is, PART n, LIST listdef-name, CLONE. SORTDEVT/SORTNUM allocate sort work. Inaccurate catalog statistics can cause the sort to fail — RUNSTATS the object if CHECK INDEX dies in SORTCHK on a huge index.
| Phase | Description |
|---|---|
| UTILINIT | Initialization |
| UNLOAD | Unload data keys from the table (or auxiliary data) |
| SORTCHK | Sort unloaded keys and scan the index to validate them |
| UTILTERM | Cleanup |
UNLOAD reads keys from the data. SORTCHK compares that sorted stream with a scan of the index. A mismatch message identifies keys in one place and not the other. DISPLAY UTILITY shows which phase is running.
REFERENCE lets applications read but not write the index, table space, or partition while it is checked. That is the simple, consistent choice for a batch window.
CHANGE lets applications read and write the live objects. The utility copies the table space/partition and indexes to shadow data sets and checks the shadows:
For CHANGE, the user ID that drives DFSMSdss needs authority to create those shadows (IBM documents RACF ALTER or equivalent on the shadow data set). Preallocate shadows on the same storage group, EA-enabled if the original is, LINEAR, SHAREOPTIONS(3,3). MODEL the new data set after the original when you define them yourself.
CHECK INDEX can process indexes in parallel. For a partitioned table space, check the partitions you care about; for nonpartitioned secondary indexes, logical partitions of the NPSI may need their own shadow pieces when you use SHRLEVEL CHANGE. One logical partition check is supported for diagnosing a single slice without checking the entire NPSI at once.
SYSPRINT lists indexes checked and any inconsistent keys. A clean run is your green light for CHECK DATA. A dirty run means:
Termination and restart rules are in the Utility Guide; after a failure, DISPLAY UTILITY and TERM UTILITY if the UID is stuck, then rerun from the correct phase.
A complete integrity sweep after PIT recover is often CHECK INDEX (all related indexes), then CHECK DATA SCOPE ALL (or PENDING), then CHECK LOB if LOB spaces were recovered independently.
The table is a box of toys. The index is a list that says “the red car is on hook 4.” CHECK INDEX walks the box and the list. If the list says hook 4 has a red car but hook 4 is empty, or a blue truck is in the box with no list line, the teacher writes a warning. The teacher does not rewrite the list — that is REBUILD INDEX, which walks every toy and makes a brand-new list. SHRLEVEL CHANGE photocopies box and list, checks the photocopy, and lets kids keep playing with the real toys.
1. What does CHECK INDEX test?
2. When should you run CHECK INDEX besides “something looks wrong”?
3. What are the CHECK INDEX phases?
4. How does SHRLEVEL CHANGE check without blocking writers for the whole job?
5. What extra check happens for an auxiliary (LOB) table index?