8
TOAST
A tuple must fit one page
some attributes can be compressed,
moved to a separate TOAST table,
or both compressed and moved
A TOAST table
is stored in the pg_toast schema
provides its own index
splits “oversized” attributes into chunks that are smaller than a page
is read only when an “oversized” attribute is queried
uses its own versioning
is seamlessly used by applications
In PostgreSQL, any row version must fit a single page. For “oversized”
tuples, the TOAST mechanism is used, which stands for “The Oversized
Attributes Storage Technique”. It implies several strategies. Some oversized
attributes can be compressed for the tuple to fit a page. If it is impossible,
the attribute can be moved into a separate service table. These two
approaches can also be combined.
If required, for each main table, PostgreSQL creates a separate TOAST
table (with a special index). Such tables and indexes are located in a
separate schema called pg_toast, so they are usually invisible.
Tuples in TOAST tables must also fit a single page, so to store oversized
values, PostgreSQL splits them into chunks. When required by an
application, these chunks are seamlessly put together to produce a full
value.
TOAST tables are accessed only if the oversized value has to be returned.
Besides, TOAST tables have their own versioning: if an update does not
affect the oversized value, the new tuple refers to the same value in the
TOAST table. This approach allows us to save some space.