You can enable compression on individual hypertables, by declaring which column you want to segment by.

This procedure uses an example table, called example, and segments it by the device_id column. Every chunk that is more than seven days old is then marked to be automatically compressed. The source data is organized like this:

8/22/2019 0:00188.2200.8
8/22/2019 0:052300.5300.9
  1. At the psql prompt, alter the table:

    ALTER TABLE example SET (
    timescaledb.compress_segmentby = 'device_id'
  2. Add a compression policy to compress chunks that are older than seven days:

    SELECT add_compression_policy('example', INTERVAL '7 days');

For more information, see the API reference for ALTER TABLE (compression) and add_compression_policy.

To view the compression policy that you've set:

WHERE proc_name='policy_compression';

For more information, see the API reference for

To remove a compression policy, use remove_compression_policy. For example, to remove a compression policy for a hypertable named cpu:

SELECT remove_compression_policy('cpu');

For more information, see the API reference for remove_compression_policy.

You can disable compression entirely on individual hypertables. This command works only if you don't currently have any compressed chunks:

ALTER TABLE <TABLE_NAME> SET (timescaledb.compress=false);

If your hypertable contains compressed chunks, you need to decompress each chunk individually before you can turn off compression.


Found an issue on this page?

Report an issue!