zstd
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_zstd | 1.1.2 | UTIL | ISC | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4030 | zstd | No | Yes | No | Yes | No | Yes | - |
| Related | gzip bzip http pg_net pg_curl pgjq pgjwt pg_smtp_client |
|---|
+varatt.h
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.2 | 1817161514 | pg_zstd | - |
| RPM | PIGSTY | 1.1.2 | 1817161514 | pg_zstd_$v | - |
| DEB | PIGSTY | 1.1.2 | 1817161514 | postgresql-$v-zstd | - |
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
| Function | Return 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
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.