DB2 10.5 for Linux, UNIX, and Windows

Index reorganization

As tables are updated, index performance can degrade.

The degradation can occur in the following ways:
Index reorganization requires:

If you specify the MINPCTUSED option on the CREATE INDEX statement, the database server automatically merges index leaf pages if a key is deleted and the free space becomes less than the specified value. This process is called online index defragmentation.

To restore index clustering, free up space, and reduce leaf levels, you can use one of the following methods:

If your primary objective is to free up space, consider the CLEANUP and RECLAIM EXTENTS options of the REORG command. See the related links for more details.

In IBM® Data Studio Version 3.1 or later, you can use the task assistant for reorganizing indexes. Task assistants can guide you through the process of setting options, reviewing the automatically generated commands to perform the task, and running these commands. For more details, see Administering databases with task assistants.

With DB2® V9.7 Fix Pack 1 and later releases, if you specify a partition with the ON DATA PARTITION clause, the REORG INDEXES ALL command that is run on a data partitioned table reorganizes the partitioned indexes for the single data partition. During index reorganization, the unaffected partitions remain read and write accessible access is restricted only to the affected partition.

REORG TABLE commands and REORG INDEXES ALL commands can be issued on a data partitioned table to concurrently reorganize different data partitions or partitioned indexes on a partition. When concurrently reorganizing data partitions or the partitioned indexes on a partition, users can access the unaffected partitions. All the following criteria must be met to issue REORG commands that operate concurrently on the same table:
  • Each REORG command must specify a different partition with the ON DATA PARTITION clause.
  • Each REORG command must use the ALLOW NO ACCESS mode to restrict access to the data partitions.
  • The partitioned table must have only partitioned indexes if you run REORG TABLE commands. No nonpartitioned indexes (except system-generated XML path indexes) can be defined on the table.
Note: The output from the REORGCHK command contains statistics and recommendations for reorganizing indexes. For a partitioned table, the output contains statistics and recommendations for reorganizing partitioned and nonpartitioned indexes. Alternatively, if the objective is to reclaim space, the RECLAIMABLE_SPACE output of the ADMIN_GET_INDEX_INFO function shows how much space is reclaimable. Use the REORG INDEXES command with the RECLAIM EXTENTS option to free this reclaimable space.

Online index reorganization

When you use the REORG INDEXES command with the ALLOW READ/WRITE ACCESS and REBUILD options, a shadow copy of the index object is built while the original index object remains available as read or write access to the table continues. If write access is allowed, then during reorganization, any changes to the underlying table that would affect the indexes are logged. The reorg operation processes these logged changes while rebuilding the indexes.

Changes to the underlying table that would affect the indexes are also written to an internal memory buffer, if such space is available for use. The internal buffer is a designated memory area that is allocated on demand from the utility heap. The use of a memory buffer enables the index reorg utility to process the changes by reading directly from memory first, and then reading through the logs, if necessary, but at a much later time. The allocated memory is freed after the reorg operation completes.

Extra storage space is required in the index tablespace to hold the shadow copy of the index. Once the shadow copy of the index is built and all logs affecting the shadow copy have been processed, then a super-exclusive lock is taken on the table and the original index is discarded. The space that was occupied by the original copy of the index object is free to be reused by any object in the same tablespace, however it is not automatically returned to the filesystem.

Online index reorganization in ALLOW WRITE ACCESS mode, with or without the CLEANUP option, is supported for spatial indexes or MDC and ITC tables.