Indexes age separately from tables. Leaf pages split, pseudo-deleted keys pile up, and sequential leaf distance grows even when the table still looks clustered. The REORG INDEX online utility on DB2 for z/OS reorganizes that index space without unloading the table. This page covers when to use it, SHRLEVEL, statistics, and how it differs from REBUILD INDEX and REORG TABLESPACE.
REORG INDEX reorganizes one index (or a partition of a partitioned index). Typical reasons:
If the table is unclustered, REORG INDEX will not put data rows back in clustering order. That is REORG TABLESPACE (with SORTDATA). If the index is missing or in rebuild-pending (RBDP) after a recover or CREATE INDEX DEFER, use REBUILD INDEX, which extracts keys from the table.
12345678910//RIX EXEC PGM=DSNUTILB,PARM='DB2A,RIXEMP' //STEPLIB DD DISP=SHR,DSN=DSN.SDSNLOAD //SYSPRINT DD SYSOUT=* //UTPRINT DD SYSOUT=* //SYSIN DD * REORG INDEX HR.IXEMPNO SHRLEVEL CHANGE STATISTICS SORTDEVT SYSDA /*
You can name INDEX creator.name, INDEXSPACE database.indexspace, PART n, LIST listdef-name, or (with the documented syntax) operate on indexes for a table space. Always include SORTDEVT (or SORTNUM) unless your shop forces UTSORTAL-style dynamic sort allocation globally.
| Value | Meaning |
|---|---|
| NONE | Build into original data sets; read during UNLOAD; no access during reload |
| REFERENCE | Shadow copy; read-only until SWITCH; materializes pending index DDL |
| CHANGE | Shadow plus log apply; read/write until drain/SWITCH |
NONE reloads into the original area. Applications can read during unload and have no access during reload. IBM states that NONE is the only access level that resets REORG-pending. With NONE, REUSE logically resets Db2-managed data sets without delete/define; omit REUSE and Db2 deletes and redefines those data sets.
REFERENCE reloads into a shadow. Read-only access during unload and reload, then a brief period of no access at SWITCH.
CHANGE keeps read and write for most of the job. Db2 records changes and applies log records iteratively, then switches. You cannot specify the UNLOAD parameter with CHANGE — unload always continues. REORG INDEX SHRLEVEL CHANGE is not restartable until the SWITCH phase; SHRLEVEL REFERENCE with NOSYSUT1 requires a phase restart from the beginning of UNLOAD if unload/build fails.
Drain options (DRAIN ALL versus DRAIN WRITERS), MAXRO, RETRY, DEADLINE, SWITCHTIME, FORCE READERS/ALL, and LASTLOG YES/NO match the online-REORG family you met on REORG TABLESPACE. Use them when SWITCH cannot break in.
REORG INDEX with SHRLEVEL REFERENCE or CHANGE materializes pending alterations on the index and can reset AREOR on that index. Pending changes to the table space or table stay pending — run REORG TABLESPACE for those.
If you REORG INDEX at partition level, pending definition changes are not materialized. SHRLEVEL NONE proceeds without materializing pending index DDL.
When pending changes are materialized, index statistics are updated even if you omit STATISTICS (default STATISTICS UPDATE ALL HISTORY ALL). Explicit STATISTICS keywords override that default.
STATISTICS collects index statistics and can REPORT them to SYSPRINT and/or UPDATE the catalog. Histogram statistics from some index rebuild paths are only rough estimates; RUNSTATS remains the way to get precise histograms.
LEAFDISTLIMIT compared LEAFDIST in SYSINDEXPART and could REORG-or-recommend (REPORTONLY). The option is deprecated; IBM’s alternative is DSNACCOX. Node ID, auxiliary, hash, and XML indexes store LEAFDIST −2, so LEAFDISTLIMIT never selected them.
CLONE reorganizes clone indexes only. LISTDEF CLONED YES is not sufficient.
UNLOAD CONTINUE is normal. UNLOAD PAUSE and UNLOAD ONLY are deprecated; IBM points you at DIAGNOSE plus TERM UTIL if you must stop after keys are unloaded.
After a point-in-time recover, CHECK INDEX (next pages) may show mismatches; REBUILD INDEX, not REORG INDEX, is the usual repair.
The table is a bookshelf of stories. The index is a card catalog. REORG TABLESPACE reshelves the books. REORG INDEX only restacks the cards so they sit in tidy drawers again. REBUILD INDEX throws the cards away and writes a new catalog by walking every book. SHRLEVEL NONE means the library closes the catalog room while you restack. CHANGE means people still check out books while you build a second catalog, then you swap drawers in one quick move.
1. When do you choose REORG INDEX instead of REORG TABLESPACE?
2. Which SHRLEVEL resets REORG-pending on the index?
3. How do REORG INDEX and REBUILD INDEX differ?
4. What happens to pending index ALTER changes with SHRLEVEL REFERENCE?
5. Is LEAFDISTLIMIT still the recommended way to decide on REORG INDEX?