Free-space and visibility maps
Overview
PostgreSQL maintains a free-space map (FSM) to locate relation pages with room for new entries, and a visibility map (VM) for heap pages known to be all-visible or all-frozen. The VM can help vacuum skip work and permit index-only scans to avoid some heap visibility checks. These are distinct metadata structures. SQLite freelist_count counts entire unused pages available for reuse, not free bytes within occupied pages and not MVCC visibility metadata.
First example
PRAGMA freelist_count;Observed SQLite result (rows in JSON):
[ [ 0 ]]How it works
The new fixture initially has no freelist pages. Deleting the large BLOB inside a transaction frees at least five pages, and rollback restores the original state. The second example returns the original count after rollback. Intermediate results are retained in validation evidence; the file-backed lab separately commits a deletion and rebuilds with VACUUM. Space reuse and file shrinkage are different outcomes.
Practical example
BEGIN;DELETE FROM st_row WHERE id=2;PRAGMA freelist_count;ROLLBACK;PRAGMA freelist_count;Observed SQLite result (rows in JSON):
[ [ 0 ]]Practice and mistakes
Practice: run the deletion in a disposable transaction and inspect the intermediate freelist count before rollback. Hint 1: inspect page_count separately. Hint 2: rollback must restore row count and page state. Never run VACUUM or destructive DELETE on an application database merely to follow this example.
PostgreSQL 17 example — NOT RUN
BEGIN;SET LOCAL statement_timeout='10s';SET LOCAL lock_timeout='2s';CREATE TEMP TABLE st_pg(id integer PRIMARY KEY, label text, body text);INSERT INTO st_pg VALUES (1,'small',repeat('a',32)),(2,'large',repeat('b',6000)),(3,'medium',repeat('c',512));SELECT pg_relation_size('st_pg','fsm'),pg_relation_size('st_pg','vm');ROLLBACK;Expected result, not executed: "Inspect fork sizes; zero is possible. This does not inspect individual map entries."