I know in SQL we can compress the text field like the following:
CREATE TABLE TableName (FieldName CHARACTER(255) WITH COMPRESSION);
I want to know how to achieve the text compression in Postgres.
PostgreSQL uses a fixed page size (commonly 8 kB), and does not allow tuples to span multiple pages. Therefore, it is not possible to store very large field values directly. To overcome this limitation, large field values are compressed and/or broken up into multiple physical rows.
In a nutshell, when a value is wider than 2 kB (set by TOAST_TUPLE_THRESHOLD ) and the default EXTENDED storage method is used, compression automatically kicks in. This information led me to ask the following questions: How much compression is achieved on TEXT ?
ZSON is a PostgreSQL extension for transparent JSONB compression. Compression is based on a shared dictionary of strings most frequently used in specific JSONB documents (not only keys, but also values, array elements, etc). In some cases ZSON can save half of your disk space and give you about 10% more TPS.
TOAST is a mechanism PostgreSQL uses to keep physical data rows from exceeding the size of a data block (typically 8KB). PostgreSQL does not support physical rows that cross block boundaries, so the block size is a hard upper limit on row size.
Compression is enabled by default for all string types, you don't have to tell the database to do it. Check the manual about TOAST
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With