REORG TABLESPACE is the DB2 utility that puts rows back in order, reclaims wasted space, and keeps large tablespaces healthy. This hands-on guide covers prerequisites, SHRLEVEL choices, a workable JCL pattern, verification, and the errors that stop beginners cold.
Over time, inserts, updates, and deletes scatter rows away from clustering sequence and leave empty holes in pages. Queries that once rode a tight clustering index start reading more pages. REORG rebuilds the physical layout: unload (often sorted by clustering key), reload, rebuild indexes, and optionally switch shadow data sets into place for online availability.
REORG is also used to materialize certain pending ALTER changes when SHRLEVEL REFERENCE or CHANGE is specified. That dual role—performance hygiene plus schema materialization—makes it a weekly staple in many shops.
Practice on a training table space first. Online REORG JCL varies by shop templates more than almost any other utility.
Check real-time statistics, REORG-recommended indicators, and application symptoms (growing getpages, declining cluster ratio). Blind REORGs waste CPU and batch windows.
1234REORG TABLESPACE TRAINING.EMPTS SHRLEVEL REFERENCE SORTDATA YES STATISTICS TABLE(ALL) INDEX(ALL)
For a partition range on a larger object:
12345REORG TABLESPACE TRAINING.EMPTS PART 10:20 SHRLEVEL CHANGE SORTDATA YES STATISTICS TABLE(ALL) INDEX(ALL)
12345678910111213141516//REORGEMP JOB (ACCT),'DB2 REORG',CLASS=A,MSGCLASS=X, // NOTIFY=&SYSUID //JOBLIB DD DISP=SHR,DSN=DSN.V13R1M0.SDSNEXIT // DD DISP=SHR,DSN=DSN.V13R1M0.SDSNLOAD //* Use your shop PROC for SORTWKnn, copy DDs, and shadows //REORG EXEC PGM=DSNUTILB,REGION=0M, // PARM='DB2T,REORGEMP' //SYSPRINT DD SYSOUT=* //UTPRINT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SYSIN DD * REORG TABLESPACE TRAINING.EMPTS SHRLEVEL REFERENCE SORTDATA YES STATISTICS TABLE(ALL) INDEX(ALL) /*
Production CHANGE reorgs usually need additional DDs for inline copies, discard/error data sets, and sort work. Copy a proven template from your DBA team rather than inventing every DD on the first try.
Typical phase names you will see in SYSPRINT include UTILINIT, UNLOAD, RELOAD, SORT, BUILD, LOGAPPLY (CHANGE), SWITCH, and UTILTERM. Long stalls often mean drain contention or sort pressure—coordinate with application owners.
123456789SELECT NAME, STATSTIME FROM SYSIBM.SYSTABLESPACE WHERE DBNAME = 'TRAINING' AND NAME = 'EMPTS'; SELECT NAME, STATSTIME, CLUSTERED FROM SYSIBM.SYSINDEXES WHERE TBCREATOR = 'TRAINING' AND TBNAME = 'EMPLOYEE';
Online REORG cannot switch while long transactions hold claims. Tune drain wait, retry windows, or schedule when batch writers quiet down.
Huge keys and SORTDATA YES need adequate SORTWK capacity. Symptoms include sort utility messages and job abends. Enlarge work files or adjust parallelism per site guidance.
Certain SHRLEVEL and object combinations require COPYDDN-style inline copies for recoverability. Add the copy DDs your template expects.
Another LOAD, REORG, or RECOVER owns the object. DISPLAY UTILITY, wait or TERM only with authority and a recovery plan.
Some CHANGE patterns need a valid mapping table. Create it ahead of time following IBM samples for your version.
A REORG that materializes pending ALTERs can change limit keys or other attributes. Know which pending changes exist before you start.
Picture a bookshelf where people keep shoving books back in the wrong order and leaving gaps. REORG takes all the books off, puts them back in neat order, and tightens the gaps so you can find stories faster. If the library must stay open (SHRLEVEL CHANGE), workers build a second neat shelf in the back, then swap it in quickly at the end. If the library can close for a while (SHRLEVEL NONE), they tidy the one shelf in place during quiet time.
1. Why do DBAs run REORG TABLESPACE?
2. Which SHRLEVEL allows read/write during most of an online REORG?
3. How can you avoid a separate RUNSTATS after REORG?
4. What is a common reason to REORG?
5. Can two REORG SHRLEVEL CHANGE PART jobs always run on different partitions of the same table space?