zstd

Zstandard compression algorithm implementation in PostgreSQL

Overview

PackageVersionCategoryLicenseLanguage
pg_zstd1.1.2UTILISCC
IDExtensionBinLibLoadCreateTrustRelocSchema
4030zstdNoYesNoYesNoYes-
Relatedgzip bzip http pg_net pg_curl pgjq pgjwt pg_smtp_client

+varatt.h

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.1.21817161514pg_zstd-
RPMPIGSTY1.1.21817161514pg_zstd_$v-
DEBPIGSTY1.1.21817161514postgresql-$v-zstd-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
u24.x86_64
u24.aarch64
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2
PIGSTY 1.1.2

Build

You can build the RPM / DEB packages for pg_zstd using pig build:

pig build pkg pg_zstd         # build RPM / DEB packages

Install

You can install pg_zstd directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_zstd;          # Install for current active PG version
pig ext install -y pg_zstd -v 18  # PG 18
pig ext install -y pg_zstd -v 17  # PG 17
pig ext install -y pg_zstd -v 16  # PG 16
pig ext install -y pg_zstd -v 15  # PG 15
pig ext install -y pg_zstd -v 14  # PG 14
dnf install -y pg_zstd_18       # PG 18
dnf install -y pg_zstd_17       # PG 17
dnf install -y pg_zstd_16       # PG 16
dnf install -y pg_zstd_15       # PG 15
dnf install -y pg_zstd_14       # PG 14
apt install -y postgresql-18-zstd   # PG 18
apt install -y postgresql-17-zstd   # PG 17
apt install -y postgresql-16-zstd   # PG 16
apt install -y postgresql-15-zstd   # PG 15
apt install -y postgresql-14-zstd   # PG 14

Create Extension:

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 Modified 2026-03-12: add pg extension catalog (95749bf)