In fact, the DB2 table is compressed by viewing the entire table, finding duplicate characters and strings, and storing those characters and strings in a compression dictionary, then, an alternative symbol of the corresponding data string stored in the dictionary is used to represent the actual data, thus compressing the data. A compressed Attribute Table must have its corresponding compression dictionary.
Enable table compression:
SQL Code
- Create TableTablename compress yes orAlter TableTablename compress Yes
Scan the table, create the corresponding compression dictionary, and execute the actual table reorganization to compress the data (each table has its own compression dictionary, and the newly inserted data will be compressed ):
SQL code
- ReorgTableTablename resetdictionary
If you want to reorganize a compressed table, instead of recreating a data dictionary, then:
SQL code
-
- ReorgTableTablename keepdictionary
Before compression, we usually want to evaluate how much space can be saved after table compression by using the DB2 inspect and db2inspf commands:
SQL code
- DB2 inspect rowcompestimate table name tbname results keep tbfile
-
- Db2inspf tbfile alantab_output_resultfile