This tutorial explores the DB2 data server Row Compression feature and the automatic compression enhancement introduced in version 9.5. Index compression feature added in DB2 version 9.7 is also demonstrated in this tutorial.

Row compression can be enabled when a table is created. The data server automatically samples new data and automatically creates a compression dictionary. When enough new data has been sampled (typically 1 - 2 MB), a compression dictionary is created. Any new incoming data is compressed automatically. You don't have to run REORG or INSPECT to explicitly create the compression dictionary.

In this tutorial, you will complete the following steps to highlight the differences between manual and automatic compression:

  1. Create an uncompressed table and populate the table with 250,000 rows.
  2. Estimate the space occupied by the table and use INSPECT to calculate projected disk saving.
  3. Create a copy of the table, populate table with data, and manually switch on compression.
  4. Find the actual size of the uncompressed table.
  5. Create a new table with automatic compression and populate it with data.
  6. Compare the disk usage by the manually and automatically compressed tables.
  7. Run REORG on the auto compressed table to reclaim initial disk space.
  8. Compare the disk usage of the auto compressed table before and after the REORG.
  9. Compare the query performance for both compressed and uncompressed tables.
  10. Create compressed indexes.