Partitioned Tablespaces

Modified on Mon, 30 Nov at 12:52 PM

Partitioning is how Db2 for z/OS handles large tables, and it is also where most utility mistakes are made. A partitioned tablespace can be partitioned by growth or by range, its indexes can be partitioned or not, and its tables can carry LOB and XML columns stored in auxiliary objects of their own. Each combination changes how COPY, REORG, RUNSTATS, LOAD, UNLOAD and DSN1COPY must be run, how the work can be split, and how much space it needs. TUC knows these rules and applies them in every decision it makes, from the policy that selects a partition to the job that processes it, so the DBA team never has to work them out object by object.

Key Benefits

Partition or Tablespace — Every utility is run at the level that is right for the object: by partition where Db2 allows it, by tablespace where it must be.

NPIs Taken Into Account — Non-partitioned indexes shape how partitions are grouped, how jobs are split and how much space a REORG needs.

Growth Without Surprises — Partition-by-growth tablespaces are watched on the partition that is still filling, and their maximum number of partitions is raised when the estimated size needs more.

LOB and XML Handled — Auxiliary objects are listed, reorganized, checked, unloaded and loaded with the options they require.

Copies That Fit — DSN1COPY adapts the target to the source: partitions added to a partition-by-growth target, limit keys aligned, pieces defined and indexes rebuilt once.

Every Special Case Covered — All of this is automatic, for every object TUC covers, including the objects created tomorrow.

Why Partitioned Tablespaces Are Different

A non-partitioned tablespace is processed as a whole. A partitioned one offers a choice, and each choice has consequences. Copying one partition at a time is fast and safe. Reorganizing one partition at a time is also possible, but every non-partitioned index on the table must then be rebuilt or updated for each one, and two jobs reorganizing partitions of the same tablespace in parallel compete for the same index. A partition-by-growth tablespace fills its last partition and spills into the next, so its partitions cannot be treated as independent. Statistics collected by partition must be rolled up into statistics for the whole table. LOB and XML columns live in separate tablespaces that have their own utilities and their own restrictions.

None of this is written in one place, and a site with thousands of partitioned objects cannot build it into every job. A job that works for one tablespace fails, or quietly does the wrong thing, for the next.


Partition Level or Object Level

TUC generates the utility statements either by partition or by object, for each utility product it supports, and chooses per case:

  • Selecting by partition. The policy evaluates every partition on its own statistics, so only the partitions that need a REORG, a copy or new statistics are selected. Thresholds can be set for a single partition, and when every partition of a tablespace is excluded, the exclusions are merged into one for the whole tablespace.
  • Processing the whole tablespace. Some work must cover every partition: a tablespace with a pending conversion to a universal tablespace, or a tablespace whose partitions are all in advisory REORG pending. TUC processes these in full, whatever the policy selected.
  • Rebalancing only on request. Redistributing rows across the partitions of a partition-by-range tablespace is never started on its own. When it is requested, TUC applies it only where at least two consecutive partitions were selected, as Db2 requires, and generates a separate statement for each such tablespace.
  • Sorting per object. Whether a REORG sorts the data is decided per tablespace from its clustering. When several objects share one statement, the most demanding choice is applied to all of them.

Non-Partitioned Indexes

Non-partitioned indexes are the main reason partitions cannot always be treated separately, and TUC accounts for them wherever they matter:

  • Grouping for REORG. All partitions of a partition-by-range tablespace that has a non-partitioned index are kept in the same job, so the index is never rebuilt by several parallel jobs at once. Without such an index, each partition can go to a different job.
  • Grouping for COPY. Partitions can be copied independently, unless an index on the table is itself copied; then the partitions stay together with it.
  • Sizing the work. When the policy measures a REORG to fit the window, the space of the non-partitioned indexes is counted once with the tablespace, and the partitioned indexes are counted with each of their partitions, so the estimated time reflects the real work.
  • Partitioned indexes. Partitioned indexes, including data-partitioned secondary indexes, follow their tablespace partition into the same job.
  • Loading. LOAD can defer the build of non-partitioned indexes, or only of the non-unique ones, so a large load is not slowed by index maintenance.
  • Space estimates. Space is estimated for each partition and for the table as a whole, because the size of a non-partitioned index depends on all the rows, not on one partition.

Partition by Growth

A partition-by-growth tablespace adds partitions as its data grows, up to its maximum number of partitions. TUC follows that behaviour:

  • Partitions stay together. All the partitions of a partition-by-growth tablespace are reorganized in the same job, so rows can still spill over into the next partition.
  • Growth is watched where it happens. Growth is measured on the last active partition, the only one that can still fill, and an early warning is given when the tablespace is about to reach its maximum space.
  • The limit follows the estimate. When TUC estimates the space a partition-by-growth tablespace needs, it also works out how many partitions the data will fill. When that is more than the maximum, the alter statements it prepares raise the maximum to match, and the allocation is sized for the last, partly filled partition.
  • Conversion. Single-table simple and segmented tablespaces can be converted to partition by growth as part of routine maintenance.

Partition by Range

A partition-by-range tablespace places each row by its key, so its partitions are fixed and its definition matters. TUC keeps both in shape:

  • Modern definitions. Range-partitioned tablespaces with absolute page numbering are switched to relative page numbering, index-controlled partitioning is converted to table-controlled partitioning, and non-segmented partitioned tablespaces become universal.
  • Rotated partitions. A partition that was just rotated and is empty is not flagged for new statistics.
  • Compression. A compression dictionary is built only by REORG or LOAD REPLACE, so every partition that holds data is reorganized when compression is introduced, and a dictionary can be copied into empty partitions.

Statistics for the Whole Table

The optimizer needs statistics for the table, not only for its partitions. TUC keeps all the partitions of a tablespace in the same RUNSTATS job, whatever its type and whatever its indexes, so the partition statistics can be rolled up into statistics for the whole table and each non-partitioned index is scanned once, not once per job. The roll-up can also be set to work when some partitions are still empty.


LOB and XML Objects

LOB and XML columns are stored in auxiliary tablespaces, and each utility treats them differently. TUC handles them wherever they appear:

  • Included in the lists. Lists of all LOB objects are created for every profile that has them, for REORG and RUNSTATS, alongside the lists of base tablespaces and partitions.
  • REORG with discard or rebalancing. Removing rows or moving them between partitions must also process the LOB data. TUC adds the option that makes the REORG process the auxiliary objects, adjusts the dataset stacking that would make such a REORG fail, and stops writing discard files for LOB tables, whose records are too long to be written.
  • Selected by their own condition. A LOB tablespace is selected for REORG when too many of its LOBs are badly chunked, a fragmentation that slows every read. LOB tablespaces that exceed their extent limit can be gathered into a profile to be reallocated, because a REORG of a LOB tablespace does not reallocate it.
  • Unloaded and loaded correctly. UNLOAD statements for tables with LOB or XML columns are generated with a column list that writes the LOB and XML data to separate files, or places it at the end of each record, and XML can be unloaded in binary form. LOAD reads those columns back from the same files. Presorting is switched off for these tables, because Db2 does not allow it.
  • Checked. The exception tables for CHECK DATA are created with their LOB tables and indexes, so tables with LOB columns can be checked like any other.

Before a recovery, TUC also warns when the selected tables have LOB or XML columns, so the auxiliary objects are not forgotten.


Copying Between Subsystems

DSN1COPY copies datasets page by page, so every source dataset must land in the right target dataset, and the target must match the source exactly. Partitioning multiplies the ways this can go wrong, and TUC handles each of them:

  • Partition by partition. Each source dataset is matched to its target partition, from the pagesets or from the latest full image copy, whether that copy was taken for the partition or for the whole tablespace.
  • A partition-by-growth source that has grown. When the source has more partitions than the target, the additional source partitions are matched to new target partitions, the datasets for them are created, and the maximum number of partitions of the target is raised when it is too low. The extra partitions are not treated as a mismatch.
  • Limit keys. For partition-by-range tablespaces, the limit keys of source and target are compared. When the source was rebalanced and they no longer match, TUC generates the statements that align the target, for table-controlled or index-controlled partitioning, and can empty the target first so that the REORG this requires is cheap.
  • Attributes compared. The number of partitions, the dataset size, the piece size, the page numbering, the page size and the other attributes that DSN1COPY depends on are compared, and objects that differ are reported and not copied page by page. For their tables, TUC prepares a query that reads the source table instead, so the data can still be moved with a cross-load into the target.
  • Datasets sized correctly. For non-partitioned objects that span several datasets, the number of pieces is worked out from the dataset or piece size, missing pieces are defined, the last piece is sized to what is left, and enough volumes are allowed for each dataset.
  • The right copy options. The number of partitions, the dataset size, the piece size and the LOB option are passed to DSN1COPY for each object.
  • Indexes rebuilt once. Indexes that are not copied are rebuilt only after the last partition of their table has been copied, not after each partition.
  • Only what is needed. When only some partitions are selected, only those partitions of the target are emptied or replaced, and tables that have not changed at the source or the target since the last copy are not copied at all.

After a utility changes partitions of a table that is also in an accelerator, only the changed partitions are reloaded, and the whole table is reloaded when all its partitions changed.


Recovery and Housekeeping

Copies of partitioned tablespaces can be taken by partition or for the whole tablespace. When old copies are cleaned up, TUC checks whether a copy was taken for the whole tablespace before it decides what can be deleted, and the cleanup can work by partition or by object. Image copy datasets are named so that each one can be related to its object and its partition.


Without and With TUC

Case Without TUC With TUC
Which partitions need workWhole tablespaces processed, or partitions listed in the job.Every partition evaluated on its own statistics.
Parallel REORG with an NPIJobs that compete for the same index.Partitions kept together in one job.
Partition-by-growth spilloverBroken by splitting partitions across jobs.All partitions reorganized together.
Running out of spaceFound when inserts fail.Warned in advance from the growth of the last partition.
Statistics for the whole tableRoll-up broken by split jobs.All partitions in one RUNSTATS job.
LOB and XML columnsOptions learned from failed jobs.Lists, options and files set automatically.
DSN1COPY to a different targetPartitions, limit keys and pieces aligned object by object.New PBG partitions added, limit keys aligned, pieces defined, indexes rebuilt once.

In short — Partitioned tablespaces, non-partitioned and partitioned indexes, and LOB and XML objects each change how Db2 utilities must run. TUC applies those rules everywhere: in what the policy selects, in how work is split into parallel jobs, in how space and time are estimated, in the options of every statement, and in how data is copied between subsystems. The special cases are handled automatically, for every object, so the DBA team does not have to remember them.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article