gzip

gzip

pg_gzip : gzip and gunzip functions.

Overview

ID Extension Package Version Category License Language
4010
gzip
pg_gzip
1.0.0
UTIL
MIT
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--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

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
MIXED
1.0.0
18
17
16
15
14
13
pg_gzip -
RPM
PGDG
1.0.0
18
17
16
15
14
13
pg_gzip_$v* -
DEB
PIGSTY
1.0.0
18
17
16
15
14
13
postgresql-$v-gzip -
Linux / PG PG18 PG17 PG16 PG15 PG14 PG13
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
PIGSTY 1.0.0
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
d12.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
d13.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
d13.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
u22.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
u22.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
u24.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
u24.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
PIGSTY 1.0.1
Package Version OS ORG SIZE File URL
pg_gzip_18 1.0.0 el8.x86_64 pigsty 13.7 KiB pg_gzip_18-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_18 1.0.0 el8.aarch64 pigsty 13.9 KiB pg_gzip_18-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_18 1.0.0 el9.x86_64 pigsty 13.6 KiB pg_gzip_18-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_18 1.0.0 el9.aarch64 pigsty 13.6 KiB pg_gzip_18-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_18 1.0.0 el10.x86_64 pigsty 13.6 KiB pg_gzip_18-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_18 1.0.0 el10.aarch64 pigsty 13.8 KiB pg_gzip_18-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-18-gzip 1.0.0 d12.x86_64 pigsty 12.3 KiB postgresql-18-gzip_1.0.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-gzip 1.0.0 d12.aarch64 pigsty 12.2 KiB postgresql-18-gzip_1.0.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-gzip 1.0.0 d13.x86_64 pigsty 12.3 KiB postgresql-18-gzip_1.0.0-1PIGSTY~trixie_amd64.deb
postgresql-18-gzip 1.0.0 d13.aarch64 pigsty 12.2 KiB postgresql-18-gzip_1.0.0-1PIGSTY~trixie_arm64.deb
postgresql-18-gzip 1.0.0 u22.x86_64 pigsty 12.7 KiB postgresql-18-gzip_1.0.0-1PIGSTY~jammy_amd64.deb
postgresql-18-gzip 1.0.0 u22.aarch64 pigsty 12.7 KiB postgresql-18-gzip_1.0.0-1PIGSTY~jammy_arm64.deb
postgresql-18-gzip 1.0.0 u24.x86_64 pigsty 12.8 KiB postgresql-18-gzip_1.0.0-1PIGSTY~noble_amd64.deb
postgresql-18-gzip 1.0.0 u24.aarch64 pigsty 12.6 KiB postgresql-18-gzip_1.0.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_gzip_17 1.0.0 el8.x86_64 pigsty 13.7 KiB pg_gzip_17-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_17 1.0.0 el8.aarch64 pigsty 13.9 KiB pg_gzip_17-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_17 1.0.0 el9.x86_64 pigsty 13.6 KiB pg_gzip_17-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_17 1.0.0 el9.aarch64 pigsty 13.6 KiB pg_gzip_17-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_17 1.0.0 el10.x86_64 pigsty 13.6 KiB pg_gzip_17-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_17 1.0.0 el10.aarch64 pigsty 13.8 KiB pg_gzip_17-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-17-gzip 1.0.1 d12.x86_64 pigsty 12.9 KiB postgresql-17-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-17-gzip 1.0.1 d12.aarch64 pigsty 12.9 KiB postgresql-17-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-17-gzip 1.0.0 d13.x86_64 pigsty 12.3 KiB postgresql-17-gzip_1.0.0-1PIGSTY~trixie_amd64.deb
postgresql-17-gzip 1.0.0 d13.aarch64 pigsty 12.2 KiB postgresql-17-gzip_1.0.0-1PIGSTY~trixie_arm64.deb
postgresql-17-gzip 1.0.1 u22.x86_64 pigsty 13.1 KiB postgresql-17-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-17-gzip 1.0.1 u22.aarch64 pigsty 13.2 KiB postgresql-17-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-17-gzip 1.0.1 u24.x86_64 pigsty 12.9 KiB postgresql-17-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-17-gzip 1.0.1 u24.aarch64 pigsty 12.8 KiB postgresql-17-gzip_1.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_gzip_16 1.0.0 el8.x86_64 pigsty 13.7 KiB pg_gzip_16-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_16 1.0.0 el8.aarch64 pigsty 13.9 KiB pg_gzip_16-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_16 1.0.0 el9.x86_64 pigsty 13.7 KiB pg_gzip_16-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_16 1.0.0 el9.aarch64 pigsty 13.6 KiB pg_gzip_16-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_16 1.0.0 el10.x86_64 pigsty 13.6 KiB pg_gzip_16-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_16 1.0.0 el10.aarch64 pigsty 13.8 KiB pg_gzip_16-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-16-gzip 1.0.1 d12.x86_64 pigsty 12.9 KiB postgresql-16-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-16-gzip 1.0.1 d12.aarch64 pigsty 12.9 KiB postgresql-16-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-16-gzip 1.0.0 d13.x86_64 pigsty 12.3 KiB postgresql-16-gzip_1.0.0-1PIGSTY~trixie_amd64.deb
postgresql-16-gzip 1.0.0 d13.aarch64 pigsty 12.2 KiB postgresql-16-gzip_1.0.0-1PIGSTY~trixie_arm64.deb
postgresql-16-gzip 1.0.1 u22.x86_64 pigsty 13.1 KiB postgresql-16-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-16-gzip 1.0.1 u22.aarch64 pigsty 13.2 KiB postgresql-16-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-16-gzip 1.0.1 u24.x86_64 pigsty 12.9 KiB postgresql-16-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-16-gzip 1.0.1 u24.aarch64 pigsty 12.8 KiB postgresql-16-gzip_1.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_gzip_15 1.0.0 el8.x86_64 pigsty 13.7 KiB pg_gzip_15-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_15 1.0.0 el8.aarch64 pigsty 13.9 KiB pg_gzip_15-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_15 1.0.0 el9.x86_64 pigsty 13.6 KiB pg_gzip_15-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_15 1.0.0 el9.aarch64 pigsty 13.6 KiB pg_gzip_15-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_15 1.0.0 el10.x86_64 pigsty 13.6 KiB pg_gzip_15-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_15 1.0.0 el10.aarch64 pigsty 13.8 KiB pg_gzip_15-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-15-gzip 1.0.1 d12.x86_64 pigsty 12.9 KiB postgresql-15-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-15-gzip 1.0.1 d12.aarch64 pigsty 12.9 KiB postgresql-15-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-15-gzip 1.0.0 d13.x86_64 pigsty 12.3 KiB postgresql-15-gzip_1.0.0-1PIGSTY~trixie_amd64.deb
postgresql-15-gzip 1.0.0 d13.aarch64 pigsty 12.2 KiB postgresql-15-gzip_1.0.0-1PIGSTY~trixie_arm64.deb
postgresql-15-gzip 1.0.1 u22.x86_64 pigsty 13.1 KiB postgresql-15-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-15-gzip 1.0.1 u22.aarch64 pigsty 13.2 KiB postgresql-15-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-15-gzip 1.0.1 u24.x86_64 pigsty 12.9 KiB postgresql-15-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-15-gzip 1.0.1 u24.aarch64 pigsty 12.8 KiB postgresql-15-gzip_1.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_gzip_14 1.0.0 el8.x86_64 pigsty 13.7 KiB pg_gzip_14-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_14 1.0.0 el8.aarch64 pigsty 13.9 KiB pg_gzip_14-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_14 1.0.0 el9.x86_64 pigsty 13.6 KiB pg_gzip_14-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_14 1.0.0 el9.aarch64 pigsty 13.6 KiB pg_gzip_14-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_14 1.0.0 el10.x86_64 pigsty 13.6 KiB pg_gzip_14-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_14 1.0.0 el10.aarch64 pigsty 13.8 KiB pg_gzip_14-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-14-gzip 1.0.1 d12.x86_64 pigsty 12.8 KiB postgresql-14-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-14-gzip 1.0.1 d12.aarch64 pigsty 12.9 KiB postgresql-14-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-14-gzip 1.0.0 d13.x86_64 pigsty 12.3 KiB postgresql-14-gzip_1.0.0-1PIGSTY~trixie_amd64.deb
postgresql-14-gzip 1.0.0 d13.aarch64 pigsty 12.2 KiB postgresql-14-gzip_1.0.0-1PIGSTY~trixie_arm64.deb
postgresql-14-gzip 1.0.1 u22.x86_64 pigsty 13.1 KiB postgresql-14-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-14-gzip 1.0.1 u22.aarch64 pigsty 13.1 KiB postgresql-14-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-14-gzip 1.0.1 u24.x86_64 pigsty 12.8 KiB postgresql-14-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-14-gzip 1.0.1 u24.aarch64 pigsty 12.8 KiB postgresql-14-gzip_1.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_gzip_13 1.0.0 el8.x86_64 pigsty 13.6 KiB pg_gzip_13-1.0.0-2PIGSTY.el8.x86_64.rpm
pg_gzip_13 1.0.0 el8.aarch64 pigsty 13.9 KiB pg_gzip_13-1.0.0-2PIGSTY.el8.aarch64.rpm
pg_gzip_13 1.0.0 el9.x86_64 pigsty 13.6 KiB pg_gzip_13-1.0.0-2PIGSTY.el9.x86_64.rpm
pg_gzip_13 1.0.0 el9.aarch64 pigsty 13.6 KiB pg_gzip_13-1.0.0-2PIGSTY.el9.aarch64.rpm
pg_gzip_13 1.0.0 el10.x86_64 pigsty 13.6 KiB pg_gzip_13-1.0.0-2PIGSTY.el10.x86_64.rpm
pg_gzip_13 1.0.0 el10.aarch64 pigsty 13.8 KiB pg_gzip_13-1.0.0-2PIGSTY.el10.aarch64.rpm
postgresql-13-gzip 1.0.1 d12.x86_64 pigsty 12.6 KiB postgresql-13-gzip_1.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-13-gzip 1.0.1 d12.aarch64 pigsty 12.7 KiB postgresql-13-gzip_1.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-13-gzip 1.0.0 d13.x86_64 pigsty 12.1 KiB postgresql-13-gzip_1.0.0-1PIGSTY~trixie_amd64.deb
postgresql-13-gzip 1.0.0 d13.aarch64 pigsty 12.2 KiB postgresql-13-gzip_1.0.0-1PIGSTY~trixie_arm64.deb
postgresql-13-gzip 1.0.1 u22.x86_64 pigsty 13.0 KiB postgresql-13-gzip_1.0.1-1PIGSTY~jammy_amd64.deb
postgresql-13-gzip 1.0.1 u22.aarch64 pigsty 13.1 KiB postgresql-13-gzip_1.0.1-1PIGSTY~jammy_arm64.deb
postgresql-13-gzip 1.0.1 u24.x86_64 pigsty 12.7 KiB postgresql-13-gzip_1.0.1-1PIGSTY~noble_amd64.deb
postgresql-13-gzip 1.0.1 u24.aarch64 pigsty 12.6 KiB postgresql-13-gzip_1.0.1-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_gzip;		# build spec not ready

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgdg pigsty -u   # add both repo and update cache

Install this extension with pig:

pig install pg_gzip;		# install via package name, for the active PG version
pig install gzip;		# install by extension name, for the current active PG version

pig install gzip -v 18;   # install for PG 18
pig install gzip -v 17;   # install for PG 17
pig install gzip -v 16;   # install for PG 16
pig install gzip -v 15;   # install for PG 15
pig install gzip -v 14;   # install for PG 14
pig 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