Skip to content

pgzstd_rs

Compress and decompress bytea values with Zstandard from PostgreSQL, including a parallel batch compressor

pgzstd_rs · Compress and decompress bytea values with Zstandard from PostgreSQL, including a parallel batch compressor

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100871pgzstd_rspgzstd_rs0.0.0UTILMITRust

PostgreSQL · 11, 12, 13, 14, 15, 16

Usage

Sources:

pgzstd_rs is a pgrx prototype for manually compressing and decompressing bytea values with Zstandard. Upstream explicitly says not to rely on it because it is not ready; use it only for evaluation with disposable data.

Compress and Restore

CREATE EXTENSION pgzstd_rs;

WITH compressed AS (
  SELECT to_zstd(convert_to('repeated repeated repeated', 'UTF8'), 3) AS value
)
SELECT convert_from(from_zstd(value), 'UTF8')
FROM compressed;

to_zstd(bytea, integer) compresses a value at the requested Zstandard level. from_zstd(bytea) returns the decompressed bytes and raises a generic decompression error for invalid input. from_maybe_zstd(bytea) returns the original bytes whenever decompression fails:

SELECT from_maybe_zstd('\x6e6f742d7a737464'::bytea);

The Rust source also declares to_zstd_parallel for batch compression. Its SQL signature is generated by the pinned pgrx toolchain; inspect \df *zstd* on the installed build and test array/null behavior before using it.

Safety and Storage

from_maybe_zstd cannot distinguish deliberately uncompressed data from corrupted or truncated compressed data, so it can silently mask corruption. Store an explicit format/version marker and checksum next to every payload; use from_zstd when a value is known to be compressed. Apply decompressed-size and resource limits before accepting untrusted frames, because a small input can expand dramatically.

Version 0.0.0 declares superuser-only installation and feature flags for PostgreSQL 11 through 16, but upstream provides no stable compatibility or upgrade contract. The API performs manual per-value compression and does not change PostgreSQL TOAST behavior. Benchmark end-to-end size, CPU, WAL, backup, replication, and query cost, and keep the original data until round-trip and disaster-recovery tests pass.

Table reader