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
|
Source
pig build pkg pg_gzip; # build spec not readyInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgdg pigsty -u # add both repo and update cacheInstall 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 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