What TOAST actually does
A PostgreSQL row lives inside a page, and a page is 8 KB by default. Tuples cannot straddle pages, so when a single column value grows beyond what fits, PostgreSQL moves it out of the main heap into a separate relation — the TOAST table. Large text, for example, gets compressed, sliced into chunks, and written somewhere else entirely. That out-of-line storage mechanism is what people mean by TOAST.
The trigger is roughly 2 KB, about a quarter of a page. Before a value is pushed out, PostgreSQL tries compression first: if the compressed form fits under the limit, the value stays in the main table. Only when compression still isn't enough does the value get split into chunks and handed to the TOAST relation.
Setting up a place to experiment
On macOS, Homebrew is the quickest route:
$ brew update
$ brew tap homebrew/core
$ brew install postgresql
$ brew services start postgresql
A dedicated role keeps things tidy:
CREATE ROLE dong WITH LOGIN PASSWORD 'password123';
ALTER ROLE dong CREATEDB;
Then a table with one variable-length column:
CREATE TABLE public.t
(
A INTEGER,
B INTEGER,
C VARCHAR
);
Not every table owns a TOAST relation. A table only gets one when it contains at least one variable-length column; tables made purely of fixed-width types have nothing to push out.
Test data that taught me a lesson
I built a long string by pasting the same Base64 block over and over, then inserted it inside a transaction:
BEGIN;
INSERT INTO t (A, B, C) VALUES (1, 1, 'eW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZckeW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZckeW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZckeW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZckeW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZckeW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZckeW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZckeW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZckeW6vtvRwaDq9nRveYLPNQ2jePsZWDmmm7t28BP8QRQMLFT5S3KVwGjsaHPxLDxjMkaR9GHn8mNXCY6ZKDkVRg7Fb2QivMeJrQJgDypLiWVKvibv8nXhy8f4XbwrvaZck');
COMMIT;
The literal above is that one block repeated — and the repetition turned out to be the whole problem. When I went looking for the value in the TOAST table, there was nothing there.
The reason is compression. A string made of the same block over and over squeezes down to almost nothing, so PostgreSQL kept it in the main heap and never bothered with out-of-line storage. If you want to reproduce the behavior, pick something like a ~100 KB image, Base64-encode it, and use that as the variable-length payload. Real image data doesn't compress away.
Finding the TOAST relation and its index
Every relation records its TOAST partner, so the lookup is straightforward:
-- the corresponding TOAST table
SELECT reltoastrelid::regclass FROM pg_class WHERE relname = 't'; -- pg_toast.pg_toast_16386
SELECT relname FROM pg_class WHERE oid = (SELECT reltoastrelid FROM pg_class WHERE relname='t'); -- pg_toast_16386
-- OIDs of the table and its TOAST table
SELECT oid FROM pg_class WHERE relname = 't'; -- 16386
SELECT oid FROM pg_class WHERE relname = 'pg_toast_16386'; -- 16389
To see both the TOAST heap and its index in one shot:
SELECT
relname,
relpages,
oid
FROM
pg_class,
( SELECT reltoastrelid FROM pg_class WHERE relname = 't' ) AS ss
WHERE
oid = ss.reltoastrelid
OR oid = ( SELECT indexrelid FROM pg_index WHERE indrelid = ss.reltoastrelid )
Output:
pg_toast_16386 0 16389
pg_toast_16386_index 1 16390
Note that the TOAST heap reports zero pages at this point — consistent with the value never having been moved out.
Reading the raw page
SELECT * FROM get_raw_page('t', 0);
On a fresh install this fails:
ERROR: function get_raw_page(unknown, integer) does not exist
LINE 1: SELECT * FROM get_raw_page('t', 0)
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
, Time: 0.002000s
The function comes from pageinspect:
-- check which extensions are installed
SELECT * FROM pg_extension;
-- install the pageinspect extension, otherwise get_raw_page() is unavailable
create EXTENSION pageinspect;
If you hit a permission error, the role needs superuser rights:
-- for an existing user
ALTER ROLE dong WITH SUPERUSER;
-- or create a new one
CREATE ROLE super WITH SUPERUSER;
Run the query again. In Navicat the column shows up as "(BLOB) 8KB" by default; switch the editor to hexadecimal display and click the BLOB cell to inspect it.

The data on the right is the string itself — the very first Base64 block — followed by a repeating . ... marker, which is how PostgreSQL represents the compressed repetition. That marker is why my earlier check found nothing in the TOAST table. Once an actual image's Base64 payload is inserted, compression can no longer bring it under the limit, and it does end up in the TOAST relation.
Looking inside the TOAST table
SELECT ctid, * FROM pg_toast.pg_toast_16386

Three columns matter here. chunk_id groups the pieces belonging to one value, chunk_seq is the position within that group, and chunk_data holds the bytes. In the first chunk (visible at the bottom right of the screenshot) you can see the payload begins with data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIA — the value was cut apart and stored piece by piece.
Four storage strategies
Out-of-line storage isn't the only option; each column can be told how to behave.
PLAIN— no compression, and never stored out of line.EXTENDED— the default: compress first, move out of line when needed.EXTERNAL— no compression, but out-of-line storage is allowed.MAIN— compression is allowed, but keeping the value in the main table takes priority; moving it out is a last resort, less eagerly thanEXTENDED.
Why does PostgreSQL avoid the cross-page approach and instead shunt big values elsewhere? The read path benefits: when a query filters rows without selecting the large column, the engine never touches it, which cuts disk I/O. The write path pays for it: inserting a large value means slicing it, inserting the chunks, and updating the TOAST index, which is slower than a plain sequential write. Reading a full row also requires locating the TOAST index entry before fetching the chunks, so sequential read performance isn't what it would be with inline storage.
For large text, VARCHAR without a length limit behaves the same as TEXT — same performance, no difference. For images, audio, video, or documents, use bytea. When a bytea value crosses the threshold and is moved out, it isn't parsed or transformed; the raw bytes go to the TOAST table as-is.
Storing an actual binary file
CREATE TABLE public.t2
(
A BYTEA
);
A small Python script does the insert:
import psycopg2
# connect to the database
conn = psycopg2.connect("dbname=tmp01 user=dong password=password123")
# get a cursor object
cur = conn.cursor()
# open the image file and read its contents
with open('1.jpg', 'rb') as f:
binary_data = f.read()
# insert statement
insert_query = "INSERT INTO t2(a) VALUES(%s)"
# execute the insert, passing the bytes
cur.execute(insert_query, (binary_data,))
# commit the transaction
conn.commit()
# close the connection
cur.close()
conn.close()
After inserting, locate the TOAST table the same way as before and inspect it. The image is stored as a series of roughly 1.95 KB records, because TOAST rows are subject to the same 2 KB per-row limit as the main table.

Changing when values get moved out
By default a column larger than 2 KB goes to the TOAST table. The cut-off can be adjusted per table:
ALTER TABLE t2 SET (toast_tuple_target=128);
The accepted range is 128 to 8160, with 8160 being the maximum row size in PostgreSQL.
In most cases there's no reason to touch it. Lowering the value can make sense when you want to free up space in the main table, keep the heap compact so single-row scans stay fast, or take advantage of the fact that TOAST rows can be updated without rewriting the entire main-table row.
It also helps to know the difference between TOAST_TUPLE_TARGET and TOAST_TUPLE_THRESHOLD. Both default to 2 KB. When a value exceeds TOAST_TUPLE_THRESHOLD, PostgreSQL attempts compression; if the compressed result is smaller than TOAST_TUPLE_TARGET, the value stays in the main table rather than being moved out.
Checking how much space each side uses
SELECT
pg_size_pretty(pg_relation_size(oid)) table_size,
pg_size_pretty(pg_relation_size(reltoastrelid)) toast_size
FROM pg_class
WHERE relname = 't';

That covers the fundamentals. The more interesting questions — how this behaves under specific workloads, and where the trade-offs actually bite — are worth a separate round of testing.