PostgreSQL: compress JSON column

Viewed 7075

I have a table with a JSON type column and I have 1 row in the table. Following request show me result 20761 bytes:

SELECT pg_column_size(test_column) FROM test_table;

The value from test_column has size 45888 bytes so it means that PostgreSQL compressed this data, but it compressed 45888/20761=~2.1 times. How can I do compression of JSON type more than existing value?

1 Answers

Changing the type to jsonb does not make it use less disk space, it might in some cases even use more. Take a look at ZSON. It is a PostgreSQL extension that compresses the JSON data by creating a lookup table for the most common data, most likely the json-keys, and it claims to be able to save up to half of the needed disk space.

Related