6
TOAST
A row version must fit into one page
some fields can be compressed
some fields can be moved into a TOAST table
fields can be both compressed and moved
TOAST table
located in the pg_toast (pg_toast_temp_N) schema
supported by its own index
contains chunks of oversized values, each chunk is smaller than a page
retrieved only when the oversized field is accessed
has its own row versions
used transparently for the application
Any row version in PostgreSQL must fit entirely into one page. Oversized
row versions are stored using TOAST, The Oversized Attributes Storage
Technique. TOAST comprises several approaches to storing oversized field
values. Firstly, the value can be compressed so that the row version fits into
the page. Secondly, the value can be moved from the row version to a
separate service table. Both strategies can be applied to the same row
versions: some values would be compressed, some moved, some
compressed and moved.
Any table can have a separate TOAST table (with a dedicated index)
created for it, if necessary. Such tables and indexes are located in a
separate schema named pg_toast and, therefore, are usually not visible (for
temporary tables, pg_toast_temp_N schema is used, similarly to the regular
pg_temp_N).
The row versions in the TOAST table must also fit into one page each, so
longer values are split into multiple chunks, and are transparently “glued
together” by PostgreSQL when the application demands.
TOAST table is used only when oversized values are accessed. Besides
that, TOAST tables have their own row versions. Whenever a data update in
the main table does not affect the oversized value, the new row version will
refer to the same TOAST value, saving disk space.