6
TOAST
A row version must fit into one page
some of the 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
accessed by querying a corresponding oversized field
has its own MVCC
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. The dedicated indexes are located in the
pg_toast schema and therefore are usually not visible (temporary TOAST
tables are stored in the pg_toast_temp_N schema, 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 tables are used only when oversized values are queried. The tables
have their own versioning mechanism. Whenever a data update in the main
table does not modify the oversized value in the TOAST table, the new row
version in the table will refer to the same old TOAST value, saving disk
space.