ALTER TABLE (Compression) Community

‘ALTER TABLE’ statement is used to turn on compression and set compression options.

The syntax is:

  1. ALTER TABLE <table_name> SET (timescaledb.compress, timescaledb.compress_orderby = '<column_name> [ASC | DESC] [ NULLS { FIRST | LAST } ] [, ...]',
  2. timescaledb.compress_segmentby = '<column_name> [, ...]'
  3. );

Required Options

NameDescription
timescaledb.compressBoolean to enable compression

Other Options

NameDescription
timescaledb.compress_orderbyOrder used by compression, specified in the same way as the ORDER BY clause in a SELECT query. The default is the descending order of the hypertable’s time column.
timescaledb.compress_segmentbyColumn 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. The default is no segment by columns.

Parameters

NameDescription
table_nameName of the hypertable that will support compression
column_nameName of the column used to order by and/or segment by

Sample Usage

Configure a hypertable that ingests device data to use compression.

  1. ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby = 'time DESC', timescaledb.compress_segmentby = 'device_id');