PostgreSQL Storage – How PostgreSQL Stores Duplicated VARCHAR Values

duplicationpostgresqlpostgresql-9.6storage

I have a VARCHAR(255) column in a table with about 50 million rows. In that column there is only 10 unique values, which act as labels. I'm wondering whether Postgres does something smart and stores only those 10 values and just references them in each row or is the data stored as 50 million values?

Best Answer

It stores what you inserted. Normalize it.

PostgreSQL may store larger text and varchar values out-of-line in a side table, possibly compressed. But not small labels.

BTW, varchar(255) has no effect in postgres, it's the same as text with a length check constraint.