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 Availability | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| 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 / 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 | 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 |
| 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 |
| 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.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.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.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.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.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 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 rpmsInstall
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 13Create 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])returnsBYTEAgzip(uncompressed TEXT, [compression_level INTEGER])returnsBYTEAgunzip(compressed BYTEA)returnsBYTEA
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