You can enable compression on individual hypertables, by declaring which column you want to segment by.
This page 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:
time | device_id | cpu | disk_io | energy_consumption |
---|---|---|---|---|
8/22/2019 0:00 | 1 | 88.2 | 20 | 0.8 |
8/22/2019 0:05 | 2 | 300.5 | 30 | 0.9 |
At the
psql
prompt, alter the table:ALTER TABLE example SET (timescaledb.compress,timescaledb.compress_segmentby = 'device_id');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:
SELECT * FROM timescaledb_information.jobsWHERE proc_name='policy_compression';
For more information, see the API reference for timescaledb_information.jobs
.
To disable a compression policy temporarily, find the corresponding job ID and then call alter_job
to pause it:
SELECT * FROM timescaledb_information.jobs where proc_name = 'policy_compression' AND relname = 'example'
SELECT alter_job(<job_id>, scheduled => false);
To enable it again:
SELECT alter_job(<job_id>, scheduled => true);
To remove a compression policy, use remove_compression_policy
:
SELECT remove_compression_policy('example');
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 <EXAMPLE> SET (timescaledb.compress=false);
If your hypertable contains compressed chunks, you need to decompress each chunk individually before you can turn off compression.
Keywords
Found an issue on this page?Report an issue or Edit this page in GitHub.