What is the size limit of a TOAST table in PostgreSQL? 4 billion rows o 4 billions values of chunk_id?
TOAST tables are defined like this:
\d pg_toast.pg_toast_59238TOAST table "pg_toast.pg_toast_59238" Column | Type ------------+--------- chunk_id | oid chunk_seq | integer chunk_data | bytea
Here chunk_id
is the identifier of a single toasted value, and chunk_seq
is the index for the parts into which the toasted value has been split.
Since there are only around 4 billion different unsigned 4-byte integers, and that is what the data type oid
is, there can be only 4 billion toasted data in each database table.
However, not each entry in a table gets toasted: only when the size of a table row exceeds 2000 bytes after compression, values are stored out of line.
You can fund the TOAST table for your table:
SELECT reltoastrelidFROM pg_classWHERE relname = 'mytable';
Then you can find how many toasted entries there are:
SELECT count(DISTINCT chunk_id)FROM pg_toast.pg_toast_12345;
Warning: That is an expensive query.