Skip to main content
Old API since v2.18.0. Superseded by ALTER TABLE (Hypercore). However, compression APIs are still supported, you do not need to migrate to the hypercore APIs. Use ‘ALTER TABLE’ to turn on compression and set compression options. By itself, this ALTER statement alone does not compress a . To do so, either create a compression policy using the add_compression_policy function or manually compress a specific using the compress_chunk function. The syntax is:
ALTER TABLE <table_name> SET (timescaledb.compress,
   timescaledb.compress_orderby = '<column_name> [ASC | DESC] [ NULLS { FIRST | LAST } ] [, ...]',
   timescaledb.compress_segmentby = '<column_name> [, ...]',
   timescaledb.compress_chunk_time_interval='interval'
);

Samples

Configure a that ingests device data to use compression. Here, if the is often queried about a specific device or set of devices, the compression should be segmented using the device_id for greater performance.
ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby = 'time DESC', timescaledb.compress_segmentby = 'device_id');
You can also specify compressed interval without changing other compression settings:
ALTER TABLE metrics SET (timescaledb.compress_chunk_time_interval = '24 hours');
To disable the previously set option, set the interval to 0:
ALTER TABLE metrics SET (timescaledb.compress_chunk_time_interval = '0');

Arguments

NameTypeDefaultRequiredDescription
timescaledb.compressBOOLEAN-Enable or disable compression
timescaledb.compress_orderbyTEXTDescending order of the ‘s time column-Order used by compression, specified in the same way as the ORDER BY clause in a SELECT query.
timescaledb.compress_segmentbyTEXTNo segment by columns-Column list on which to key the compressed segments. An identifier representing the source of the data such as device_id or tags_id is usually a good candidate.
timescaledb.compress_chunk_time_intervalTEXT--EXPERIMENTAL: Set compressed time interval used to roll s into. This parameter compresses every , and then irreversibly merges it into a previous adjacent if possible, to reduce the total number of s in the . Note that s will not be split up during decompression. It should be set to a multiple of the current interval. This option can be changed independently of other compression settings and does not require the timescaledb.compress argument.

Parameters

NameTypeDescription
table_nameTEXT that supports compression
column_nameTEXTColumn used to order by or segment by
intervalTEXTTime interval used to roll compressed s into