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:
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 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.
Keywords
Found an issue on this page?
Report an issue!