pg_column_compression()

A function returning the compression algorithm used on a TOAST value
This entry relates to a PostgreSQL feature which is part of PostgreSQL 14, due to be released in late 2021.

pg_column_compression() is a system function returning the compression algorithm used to compress a TOAST value.

pg_column_compression() was added in PostgreSQL 14.

Usage

pg_column_compression ( "any" ) → text

If a value was not compressed, NULL is returned.

Change history

Examples

Example of pg_column_compression(), with a value where no compression took place, a value which was compressed with the default pglz algorithm, and a column compressed with lz4:

postgres=# CREATE TABLE foo (id INT, val TEXT);
CREATE TABLE

postgres=# INSERT INTO foo values (1, 'bar');
INSERT 0 1

postgres=# INSERT INTO foo values (2, REPEAT('bar', 3072));
INSERT 0 1

postgres=# ALTER TABLE foo ALTER COLUMN val SET COMPRESSION lz4;
ALTER TABLE

postgres=# INSERT INTO foo values (3, REPEAT('baz', 3072));
INSERT 0 1

postgres=# SELECT id, pg_column_compression(val) FROM foo;
 id | pg_column_compression 
----+-----------------------
  1 | 
  2 | pglz
  3 | lz4
(3 rows)

Categories

System function

See also

default_toast_compression, pg_column_size()