Compressing your data

You can reduce the space required for a table by using data compression. Compressing the data in a table space can significantly reduce the amount of disk space that is needed to store data and can help improve buffer pool performance.

Before you begin

You can use the DSN1COMP utility to determine how well compression of your data will work. Data in a LOB table space or a table space that is defined in the work file database (the table space for declared temporary tables) cannot be compressed. For more information, see DSN1COMP.

Start of changeThe CPU cost of both compression and decompression increases with smaller compression ratios. Therefore, it is best to avoid the use of compression if the compression ratio, or the percentage of saved space due to compression, is less than 10 - 20 percent. The additional CPU cost for compression and decompression makes it not worthwhile.End of change

About this task

When you compress data, bit strings that occur frequently are replaced by shorter strings. Information about the mapping of bit strings to their replacements is stored in a compression dictionary. Computer processing is required to compress data before it is stored and to decompress the data when it is retrieved from storage. In many cases, using the COMPRESS clause can significantly reduce the amount of disk space needed to store data, but the compression ratio that you achieve depends on the characteristics of your data.

With compressed data, you might see some of the following performance benefits, depending on the SQL workload and the amount of compression:
  • Higher buffer pool hit ratios
  • Fewer I/Os
  • Fewer getpage operations

Procedure

To compress data:

  1. Specify COMPRESS YES in one of the following SQL statements:
    • CREATE TABLESPACE
    • ALTER TABLESPACE
  2. Populate the table space with data by taking one of the following actions:
    • Run the LOAD utility with REPLACE, RESUME NO, or RESUME YES SHRLEVEL CHANGE, and without KEEPDICTIONARY.
    • Run the REORG utility without KEEPDICTIONARY.
    • Start of changeIssue INSERT statements.End of change
    • Start of changeIssue MERGE statements.End of change
    If no compression dictionary already exists, and the amount of data in the tables space reaches a threshold determined by DB2, a compression dictionary is created. After the compression dictionary is built, DB2 uses it to compress all subsequent data added to the table space.