zstd

Zstandard compression algorithm implementation in PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4030
zstd
pg_zstd
1.1.2
UTIL
ISC
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
gzip
bzip
http
pg_net
pg_curl
pgjq
pgjwt
pg_smtp_client

+varatt.h

Packages

TypeRepoVersionPG Major AvailabilityPackage PatternDependencies
EL
PIGSTY
1.1.2
18
17
16
15
14
13
pg_zstd_$v*-
Debian
PIGSTY
1.1.2
18
17
16
15
14
13
postgresql-$v-zstd-
Linux / PGPG18PG17PG16PG15PG14PG13
el8.x86_64
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
el8.aarch64
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
el9.x86_64
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
el9.aarch64
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
el10.x86_64
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
el10.aarch64
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
d12.x86_64
MISS
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
d12.aarch64
MISS
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
d13.x86_64
MISS
MISS
MISS
MISS
MISS
MISS
d13.aarch64
MISS
MISS
MISS
MISS
MISS
MISS
u22.x86_64
MISS
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
u22.aarch64
MISS
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
u24.x86_64
MISS
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
u24.aarch64
MISS
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PackageVersionOSORGSIZEFile URL
pg_zstd_181.1.2el8.x86_64pigsty12.2 KiBpg_zstd_18-1.1.2-1PIGSTY.el8.x86_64.rpm
pg_zstd_181.1.2el8.aarch64pigsty12.2 KiBpg_zstd_18-1.1.2-1PIGSTY.el8.aarch64.rpm
pg_zstd_181.1.2el9.x86_64pigsty11.8 KiBpg_zstd_18-1.1.2-1PIGSTY.el9.x86_64.rpm
pg_zstd_181.1.2el9.aarch64pigsty11.7 KiBpg_zstd_18-1.1.2-1PIGSTY.el9.aarch64.rpm
pg_zstd_181.1.2el10.x86_64pigsty11.8 KiBpg_zstd_18-1.1.2-1PIGSTY.el10.x86_64.rpm
pg_zstd_181.1.2el10.aarch64pigsty11.8 KiBpg_zstd_18-1.1.2-1PIGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
pg_zstd_171.1.2el8.x86_64pigsty12.2 KiBpg_zstd_17-1.1.2-1PIGSTY.el8.x86_64.rpm
pg_zstd_171.1.2el8.aarch64pigsty12.2 KiBpg_zstd_17-1.1.2-1PIGSTY.el8.aarch64.rpm
pg_zstd_171.1.2el9.x86_64pigsty12.0 KiBpg_zstd_17-1.1.2-1PIGSTY.el9.x86_64.rpm
pg_zstd_171.1.2el9.aarch64pigsty11.8 KiBpg_zstd_17-1.1.2-1PIGSTY.el9.aarch64.rpm
pg_zstd_171.1.2el10.x86_64pigsty11.9 KiBpg_zstd_17-1.1.2-1PIGSTY.el10.x86_64.rpm
pg_zstd_171.1.2el10.aarch64pigsty12.0 KiBpg_zstd_17-1.1.2-1PIGSTY.el10.aarch64.rpm
postgresql-17-zstd1.1.2d12.x86_64pigsty11.9 KiBpostgresql-17-zstd_1.1.2-2PIGSTY~bookworm_amd64.deb
postgresql-17-zstd1.1.2d12.aarch64pigsty11.8 KiBpostgresql-17-zstd_1.1.2-2PIGSTY~bookworm_arm64.deb
postgresql-17-zstd1.1.2u22.x86_64pigsty12.7 KiBpostgresql-17-zstd_1.1.2-2PIGSTY~jammy_amd64.deb
postgresql-17-zstd1.1.2u22.aarch64pigsty12.5 KiBpostgresql-17-zstd_1.1.2-2PIGSTY~jammy_arm64.deb
postgresql-17-zstd1.1.2u24.x86_64pigsty12.4 KiBpostgresql-17-zstd_1.1.2-2PIGSTY~noble_amd64.deb
postgresql-17-zstd1.1.2u24.aarch64pigsty12.3 KiBpostgresql-17-zstd_1.1.2-2PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_zstd_161.1.2el8.x86_64pigsty12.2 KiBpg_zstd_16-1.1.2-1PIGSTY.el8.x86_64.rpm
pg_zstd_161.1.2el8.aarch64pigsty12.2 KiBpg_zstd_16-1.1.2-1PIGSTY.el8.aarch64.rpm
pg_zstd_161.1.2el9.x86_64pigsty12.0 KiBpg_zstd_16-1.1.2-1PIGSTY.el9.x86_64.rpm
pg_zstd_161.1.2el9.aarch64pigsty11.8 KiBpg_zstd_16-1.1.2-1PIGSTY.el9.aarch64.rpm
pg_zstd_161.1.2el10.x86_64pigsty11.9 KiBpg_zstd_16-1.1.2-1PIGSTY.el10.x86_64.rpm
pg_zstd_161.1.2el10.aarch64pigsty11.9 KiBpg_zstd_16-1.1.2-1PIGSTY.el10.aarch64.rpm
postgresql-16-zstd1.1.2d12.x86_64pigsty11.9 KiBpostgresql-16-zstd_1.1.2-2PIGSTY~bookworm_amd64.deb
postgresql-16-zstd1.1.2d12.aarch64pigsty11.8 KiBpostgresql-16-zstd_1.1.2-2PIGSTY~bookworm_arm64.deb
postgresql-16-zstd1.1.2u22.x86_64pigsty12.7 KiBpostgresql-16-zstd_1.1.2-2PIGSTY~jammy_amd64.deb
postgresql-16-zstd1.1.2u22.aarch64pigsty12.5 KiBpostgresql-16-zstd_1.1.2-2PIGSTY~jammy_arm64.deb
postgresql-16-zstd1.1.2u24.x86_64pigsty12.4 KiBpostgresql-16-zstd_1.1.2-2PIGSTY~noble_amd64.deb
postgresql-16-zstd1.1.2u24.aarch64pigsty12.3 KiBpostgresql-16-zstd_1.1.2-2PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_zstd_151.1.2el8.x86_64pigsty12.2 KiBpg_zstd_15-1.1.2-1PIGSTY.el8.x86_64.rpm
pg_zstd_151.1.2el8.aarch64pigsty12.2 KiBpg_zstd_15-1.1.2-1PIGSTY.el8.aarch64.rpm
pg_zstd_151.1.2el9.x86_64pigsty12.0 KiBpg_zstd_15-1.1.2-1PIGSTY.el9.x86_64.rpm
pg_zstd_151.1.2el9.aarch64pigsty11.8 KiBpg_zstd_15-1.1.2-1PIGSTY.el9.aarch64.rpm
pg_zstd_151.1.2el10.x86_64pigsty11.9 KiBpg_zstd_15-1.1.2-1PIGSTY.el10.x86_64.rpm
pg_zstd_151.1.2el10.aarch64pigsty11.9 KiBpg_zstd_15-1.1.2-1PIGSTY.el10.aarch64.rpm
postgresql-15-zstd1.1.2d12.x86_64pigsty11.9 KiBpostgresql-15-zstd_1.1.2-2PIGSTY~bookworm_amd64.deb
postgresql-15-zstd1.1.2d12.aarch64pigsty11.8 KiBpostgresql-15-zstd_1.1.2-2PIGSTY~bookworm_arm64.deb
postgresql-15-zstd1.1.2u22.x86_64pigsty12.7 KiBpostgresql-15-zstd_1.1.2-2PIGSTY~jammy_amd64.deb
postgresql-15-zstd1.1.2u22.aarch64pigsty12.5 KiBpostgresql-15-zstd_1.1.2-2PIGSTY~jammy_arm64.deb
postgresql-15-zstd1.1.2u24.x86_64pigsty12.4 KiBpostgresql-15-zstd_1.1.2-2PIGSTY~noble_amd64.deb
postgresql-15-zstd1.1.2u24.aarch64pigsty12.2 KiBpostgresql-15-zstd_1.1.2-2PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_zstd_141.1.2el8.x86_64pigsty12.2 KiBpg_zstd_14-1.1.2-1PIGSTY.el8.x86_64.rpm
pg_zstd_141.1.2el8.aarch64pigsty12.2 KiBpg_zstd_14-1.1.2-1PIGSTY.el8.aarch64.rpm
pg_zstd_141.1.2el9.x86_64pigsty12.0 KiBpg_zstd_14-1.1.2-1PIGSTY.el9.x86_64.rpm
pg_zstd_141.1.2el9.aarch64pigsty11.8 KiBpg_zstd_14-1.1.2-1PIGSTY.el9.aarch64.rpm
pg_zstd_141.1.2el10.x86_64pigsty11.9 KiBpg_zstd_14-1.1.2-1PIGSTY.el10.x86_64.rpm
pg_zstd_141.1.2el10.aarch64pigsty11.9 KiBpg_zstd_14-1.1.2-1PIGSTY.el10.aarch64.rpm
postgresql-14-zstd1.1.2d12.x86_64pigsty11.9 KiBpostgresql-14-zstd_1.1.2-2PIGSTY~bookworm_amd64.deb
postgresql-14-zstd1.1.2d12.aarch64pigsty11.8 KiBpostgresql-14-zstd_1.1.2-2PIGSTY~bookworm_arm64.deb
postgresql-14-zstd1.1.2u22.x86_64pigsty12.6 KiBpostgresql-14-zstd_1.1.2-2PIGSTY~jammy_amd64.deb
postgresql-14-zstd1.1.2u22.aarch64pigsty12.4 KiBpostgresql-14-zstd_1.1.2-2PIGSTY~jammy_arm64.deb
postgresql-14-zstd1.1.2u24.x86_64pigsty12.4 KiBpostgresql-14-zstd_1.1.2-2PIGSTY~noble_amd64.deb
postgresql-14-zstd1.1.2u24.aarch64pigsty12.2 KiBpostgresql-14-zstd_1.1.2-2PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_zstd_131.1.2el8.x86_64pigsty12.1 KiBpg_zstd_13-1.1.2-1PIGSTY.el8.x86_64.rpm
pg_zstd_131.1.2el8.aarch64pigsty12.2 KiBpg_zstd_13-1.1.2-1PIGSTY.el8.aarch64.rpm
pg_zstd_131.1.2el9.x86_64pigsty11.9 KiBpg_zstd_13-1.1.2-1PIGSTY.el9.x86_64.rpm
pg_zstd_131.1.2el9.aarch64pigsty11.8 KiBpg_zstd_13-1.1.2-1PIGSTY.el9.aarch64.rpm
pg_zstd_131.1.2el10.x86_64pigsty11.9 KiBpg_zstd_13-1.1.2-1PIGSTY.el10.x86_64.rpm
pg_zstd_131.1.2el10.aarch64pigsty11.9 KiBpg_zstd_13-1.1.2-1PIGSTY.el10.aarch64.rpm
postgresql-13-zstd1.1.2d12.x86_64pigsty11.8 KiBpostgresql-13-zstd_1.1.2-2PIGSTY~bookworm_amd64.deb
postgresql-13-zstd1.1.2d12.aarch64pigsty11.8 KiBpostgresql-13-zstd_1.1.2-2PIGSTY~bookworm_arm64.deb
postgresql-13-zstd1.1.2u22.x86_64pigsty12.4 KiBpostgresql-13-zstd_1.1.2-2PIGSTY~jammy_amd64.deb
postgresql-13-zstd1.1.2u22.aarch64pigsty12.4 KiBpostgresql-13-zstd_1.1.2-2PIGSTY~jammy_arm64.deb
postgresql-13-zstd1.1.2u24.x86_64pigsty12.3 KiBpostgresql-13-zstd_1.1.2-2PIGSTY~noble_amd64.deb
postgresql-13-zstd1.1.2u24.aarch64pigsty12.2 KiBpostgresql-13-zstd_1.1.2-2PIGSTY~noble_arm64.deb

Source

pig build get zstd; # get zstd source code
pig build dep zstd; # install build dependencies
pig build pkg zstd; # build extension rpm or deb
pig build ext zstd; # build extension rpms

Install

To add the required PGDG / PIGSTY upstream repository, use:

pig repo add pgsql -u   # add PGDG + Pigsty repo and update cache (leave existing repos)

Install this extension with:

pig ext install zstd; # install by extension name, for the current active PG version
pig ext install pg_zstd; # install via package alias, for the active PG version
pig ext install zstd -v 18;   # install for PG 18
pig ext install zstd -v 17;   # install for PG 17
pig ext install zstd -v 16;   # install for PG 16
pig ext install zstd -v 15;   # install for PG 15
pig ext install zstd -v 14;   # install for PG 14
pig ext install zstd -v 13;   # install for PG 13

Create this extension with:

CREATE EXTENSION zstd;

Usage

FunctionReturn Type
zstd_compress(data bytea [, dictionary bytea [, level integer ]])bytea
zstd_decompress(data bytea [, dictionary bytea ])bytea
zstd_length(data bytea)integer

zstd_compress compresses the provided data and returns a Zstandard frame. A preset dictionary may also be provided. The default compression level may also be overriden, valid values range from 1 (best speed) to 22 (best compression). The default level is 3.

If you want to override the compression level without using a dictionary, set dictionary to NULL.

zstd_decompress decompresses the provided Zstandard frame in data and returns the uncompressed data. A preset dictionary, matching the dictionary used to compress the data, may also be provided.

zstd_length returns the decompressed length of the provided Zstandard frame. If ZSTD_getFrameContentSize() is available it returns NULL if the length is unknown. If unavailable, it isn’t possible to distinguish the error, unknown decompressed length and zero decompressed length cases.

Example

Basic compress/decompress example:

CREATE EXTENSION zstd;

SELECT zstd_compress('hello world');
-- zstd_compress
-- --------------------------------------------
-- \x28b52ffd200b59000068656c6c6f20776f726c64

SELECT convert_from(zstd_decompress('\x28b52ffd200b59000068656c6c6f20776f726c64'), 'utf-8');
-- convert_from
-- --------------
--  hello world

Compress with level (1 for best speed, 22 for best compression, default to 3)

CREATE EXTENSION zstd;

SELECT zstd_compress('hello world',  NULL, 10);
-- zstd_compress
-- --------------------------------------------
-- \x28b52ffd200b59000068656c6c6f20776f726c64

SELECT convert_from(zstd_decompress('\x28b52ffd200b59000068656c6c6f20776f726c64'), 'utf-8');
-- convert_from
-- --------------
--  hello world
Last updated on