gzip

gzip and gunzip functions.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4010
gzip
pg_gzip
1.0.0
UTIL
MIT
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
bzip
zstd
http
pg_net
pg_curl
pgjq
pgjwt
pg_smtp_client

Packages

TypeRepoVersionPG Major AvailabilityPackage PatternDependencies
EL
PGDG
1.0.0
18
17
16
15
14
13
pg_gzip_$v*-
Debian
PIGSTY
1.0.0
18
17
16
15
14
13
postgresql-$v-gzip-
Linux / PGPG18PG17PG16PG15PG14PG13
el8.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el8.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el9.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el9.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el10.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el10.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d12.x86_64
MISS
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
d12.aarch64
MISS
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
d13.x86_64
MISS
MISS
MISS
MISS
MISS
MISS
d13.aarch64
MISS
MISS
MISS
MISS
MISS
MISS
u22.x86_64
MISS
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
u22.aarch64
MISS
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
u24.x86_64
MISS
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
u24.aarch64
MISS
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PackageVersionOSORGSIZEFile URL
pg_gzip_181.0.0el8.x86_64pigsty13.7 KiBpg_gzip_18-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_181.0.0el8.aarch64pigsty13.9 KiBpg_gzip_18-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_181.0.0el9.x86_64pigsty13.6 KiBpg_gzip_18-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_181.0.0el9.aarch64pigsty13.6 KiBpg_gzip_18-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_181.0.0el10.x86_64pigsty13.6 KiBpg_gzip_18-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_181.0.0el10.aarch64pigsty13.8 KiBpg_gzip_18-1.0.0-2PIGSTY.el10.aarch64.rpm
PackageVersionOSORGSIZEFile URL
pg_gzip_171.0.0el8.x86_64pigsty13.7 KiBpg_gzip_17-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_171.0.0el8.aarch64pigsty13.9 KiBpg_gzip_17-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_171.0.0el9.x86_64pigsty13.6 KiBpg_gzip_17-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_171.0.0el9.aarch64pigsty13.6 KiBpg_gzip_17-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_171.0.0el10.x86_64pigsty13.6 KiBpg_gzip_17-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_171.0.0el10.aarch64pigsty13.8 KiBpg_gzip_17-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-17-gzip1.0.1d12.x86_64pigsty12.9 KiBpostgresql-17-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-17-gzip1.0.1d12.aarch64pigsty12.9 KiBpostgresql-17-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-17-gzip1.0.1u22.x86_64pigsty13.1 KiBpostgresql-17-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-17-gzip1.0.1u22.aarch64pigsty13.2 KiBpostgresql-17-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-17-gzip1.0.1u24.x86_64pigsty12.9 KiBpostgresql-17-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-17-gzip1.0.1u24.aarch64pigsty12.8 KiBpostgresql-17-gzip_1.0.1-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_gzip_161.0.0el8.x86_64pigsty13.7 KiBpg_gzip_16-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_161.0.0el8.aarch64pigsty13.9 KiBpg_gzip_16-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_161.0.0el9.x86_64pigsty13.7 KiBpg_gzip_16-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_161.0.0el9.aarch64pigsty13.6 KiBpg_gzip_16-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_161.0.0el10.x86_64pigsty13.6 KiBpg_gzip_16-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_161.0.0el10.aarch64pigsty13.8 KiBpg_gzip_16-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-16-gzip1.0.1d12.x86_64pigsty12.9 KiBpostgresql-16-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-16-gzip1.0.1d12.aarch64pigsty12.9 KiBpostgresql-16-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-16-gzip1.0.1u22.x86_64pigsty13.1 KiBpostgresql-16-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-16-gzip1.0.1u22.aarch64pigsty13.2 KiBpostgresql-16-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-16-gzip1.0.1u24.x86_64pigsty12.9 KiBpostgresql-16-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-16-gzip1.0.1u24.aarch64pigsty12.8 KiBpostgresql-16-gzip_1.0.1-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_gzip_151.0.0el8.x86_64pigsty13.7 KiBpg_gzip_15-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_151.0.0el8.aarch64pigsty13.9 KiBpg_gzip_15-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_151.0.0el9.x86_64pigsty13.6 KiBpg_gzip_15-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_151.0.0el9.aarch64pigsty13.6 KiBpg_gzip_15-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_151.0.0el10.x86_64pigsty13.6 KiBpg_gzip_15-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_151.0.0el10.aarch64pigsty13.8 KiBpg_gzip_15-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-15-gzip1.0.1d12.x86_64pigsty12.9 KiBpostgresql-15-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-15-gzip1.0.1d12.aarch64pigsty12.9 KiBpostgresql-15-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-15-gzip1.0.1u22.x86_64pigsty13.1 KiBpostgresql-15-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-15-gzip1.0.1u22.aarch64pigsty13.2 KiBpostgresql-15-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-15-gzip1.0.1u24.x86_64pigsty12.9 KiBpostgresql-15-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-15-gzip1.0.1u24.aarch64pigsty12.8 KiBpostgresql-15-gzip_1.0.1-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_gzip_141.0.0el8.x86_64pigsty13.7 KiBpg_gzip_14-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_141.0.0el8.aarch64pigsty13.9 KiBpg_gzip_14-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_141.0.0el9.x86_64pigsty13.6 KiBpg_gzip_14-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_141.0.0el9.aarch64pigsty13.6 KiBpg_gzip_14-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_141.0.0el10.x86_64pigsty13.6 KiBpg_gzip_14-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_141.0.0el10.aarch64pigsty13.8 KiBpg_gzip_14-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-14-gzip1.0.1d12.x86_64pigsty12.8 KiBpostgresql-14-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-14-gzip1.0.1d12.aarch64pigsty12.9 KiBpostgresql-14-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-14-gzip1.0.1u22.x86_64pigsty13.1 KiBpostgresql-14-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-14-gzip1.0.1u22.aarch64pigsty13.1 KiBpostgresql-14-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-14-gzip1.0.1u24.x86_64pigsty12.8 KiBpostgresql-14-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-14-gzip1.0.1u24.aarch64pigsty12.8 KiBpostgresql-14-gzip_1.0.1-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_gzip_131.0.0el8.x86_64pigsty13.6 KiBpg_gzip_13-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_131.0.0el8.aarch64pigsty13.9 KiBpg_gzip_13-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_131.0.0el9.x86_64pigsty13.6 KiBpg_gzip_13-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_131.0.0el9.aarch64pigsty13.6 KiBpg_gzip_13-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_131.0.0el10.x86_64pigsty13.6 KiBpg_gzip_13-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_131.0.0el10.aarch64pigsty13.8 KiBpg_gzip_13-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-13-gzip1.0.1d12.x86_64pigsty12.6 KiBpostgresql-13-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-13-gzip1.0.1d12.aarch64pigsty12.7 KiBpostgresql-13-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-13-gzip1.0.1u22.x86_64pigsty13.0 KiBpostgresql-13-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-13-gzip1.0.1u22.aarch64pigsty13.1 KiBpostgresql-13-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-13-gzip1.0.1u24.x86_64pigsty12.7 KiBpostgresql-13-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-13-gzip1.0.1u24.aarch64pigsty12.6 KiBpostgresql-13-gzip_1.0.1-1PIGSTY~noble_arm64.deb

Source

pig build get gzip; # get gzip source code
pig build dep gzip; # install build dependencies
pig build pkg gzip; # build extension rpm or deb
pig build ext gzip; # 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 gzip; # install by extension name, for the current active PG version
pig ext install pg_gzip; # install via package alias, for the active PG version
pig ext install gzip -v 18;   # install for PG 18
pig ext install gzip -v 17;   # install for PG 17
pig ext install gzip -v 16;   # install for PG 16
pig ext install gzip -v 15;   # install for PG 15
pig ext install gzip -v 14;   # install for PG 14
pig ext install gzip -v 13;   # install for PG 13

Create this extension with:

CREATE EXTENSION gzip;

Usage

Sometimes you just need to compress your bytea object before you return it to the client.

Sometimes you receive a compressed bytea from the client, and you have to uncompress it before you can work with it.

This extension is for that.

This extension is not for storage compression. PostgreSQL already does tuple compression on the fly if your tuple gets large enough, manually pre-compressing your data using this function won’t make things smaller.

  • gzip(uncompressed BYTEA, [compression_level INTEGER]) returns BYTEA
  • gzip(uncompressed TEXT, [compression_level INTEGER]) returns BYTEA
  • gunzip(compressed BYTEA) returns BYTEA

Examples

> SELECT gzip('this is my this is my this is my this is my text');

                                   gzip
--------------------------------------------------------------------------
 \x1f8b08000000000000132bc9c82c5600a2dc4a851282ccd48a12002e7a22ff30000000

Wait, what, the compressed output is longer?!? No, it only looks that way, because in hex every byte is represented with two hex digits. The original string looks like this in hex:

> SELECT 'this is my this is my this is my this is my text'::bytea;

                                               bytea
----------------------------------------------------------------------------------------------------
 \x74686973206973206d792074686973206973206d792074686973206973206d792074686973206973206d792074657874

For really long, repetitive things, compression naturally works like a charm:

> SELECT gzip(repeat('this is my ', 100));

                                               bytea
----------------------------------------------------------------------------------------------------
 \x1f8b08000000000000132bc9c82c5600a2dc4a859251e628739439ca24970900d1341c5c4c040000

To convert a bytea back into an equivalent text you must use the encode() function with the escape encoding.

> SELECT encode('test text'::bytea, 'escape');
   encode
-----------
 test text

> SELECT encode(gunzip(gzip('this text has been compressed and then decompressed')), 'escape')

                      encode
-----------------------------------------------------
 this text has been compressed and then decompressed
Last updated on