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

FL 504The TS_COMPRESSION_TYPE subsystem parameter specifies the default compression algorithm that is used to compress Db2 data at the subsystem level.

FL 509 The COMPRESS option of the ALTER TABLESPACE, CREATE TABLE, and CREATE TABLESPACE statements can define the compression algorithm that is used to compress Db2 data at the table space or partition level.

Start of changeYou can use the DSN1COMP utility to determine how well compression of your data will work.End of change

Start of changeFor fixed-length compression, the 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

Start of changeIn general, Huffman compression provides better compression ratios, but has a higher CPU cost than fixed-length for decompression.End of change

Start of changeData in a table space that is defined in the work file database (the table space for declared temporary tables) cannot be compressed. End of change

About this task

Start of changeWhen 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 that is retrieved from a page in the buffer pool. 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.End of change

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:

Start of changeComplete one of the following tasks: End of change