zstd
ZSTD压缩解压缩函数包
仓库
grahamedgecombe/pgzstd
https://github.com/grahamedgecombe/pgzstd
源码
pgzstd-1.1.2.tar.gz
pgzstd-1.1.2.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pg_zstd | 1.1.2 | UTIL | ISC | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 4030 | zstd | 否 | 是 | 否 | 是 | 否 | 是 | - |
| 相关扩展 | gzip bzip http pg_net pg_curl pgjq pgjwt pg_smtp_client |
|---|
+varatt.h
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| 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 | - |
构建
您可以使用 pig build 命令构建 pg_zstd 扩展的 RPM / DEB 包:
pig build pkg pg_zstd # 构建 RPM / DEB 包
安装
您可以直接安装 pg_zstd 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install pg_zstd; # 当前活跃 PG 版本安装
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 zstd;
用法
| 函数 | 返回类型 |
|---|---|
zstd_compress(data bytea [, dictionary bytea [, level integer ]]) | bytea |
zstd_decompress(data bytea [, dictionary bytea ]) | bytea |
zstd_length(data bytea) | integer |
zstd_compress 对提供的 data 进行压缩,返回一个 Zstandard 帧。可以选择提供预设的 dictionary(字典)。也可以覆盖默认的压缩 level(级别),有效值范围为 1(最快速度)到 22(最高压缩率),默认级别为 3。
如果需要在不使用字典的情况下覆盖压缩级别,请将 dictionary 设置为 NULL。
zstd_decompress 对 data 中提供的 Zstandard 帧进行解压缩,返回解压后的数据。可以选择提供与压缩时相同的预设 dictionary(字典)。
zstd_length 返回给定 Zstandard 帧的解压后长度。如果 ZSTD_getFrameContentSize() 可用,当长度未知时返回 NULL。如果该函数不可用,则无法区分错误、未知解压长度和零解压长度这几种情况。
示例
基本的压缩/解压缩示例:
CREATE EXTENSION zstd;
SELECT zstd_compress('hello world');
-- zstd_compress
-- --------------------------------------------
-- \x28b52ffd200b59000068656c6c6f20776f726c64
SELECT convert_from(zstd_decompress('\x28b52ffd200b59000068656c6c6f20776f726c64'), 'utf-8');
-- convert_from
-- --------------
-- hello world
指定压缩级别(1 为最快速度,22 为最高压缩率,默认为 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