Goal: distinguish dead versions, reusable space, and file size by measuring each stage.
The fixture contains 20,000 wide rows with a primary-key B-tree. Autovacuum is disabled only on this fixture to keep the before/after comparison controlled. pg_relation_size measures the main fork of one relation; pg_total_relation_size includes heap, auxiliary storage, TOAST, and indexes. The provided baseline stores the initial sizes for later comparisons. Bytes are exact file lengths, not counts of useful row data.
All hints run at the Linux shell. psql -c executes quoted SQL and exits; each command uses a new connection. -U postgres explicitly selects the administrative SQL role, and -v ON_ERROR_STOP=1 stops on SQL errors. The monitoring tables are separate provided fixtures, not the baked business datasets.
Goal: observe that deleting most rows does not immediately compact the files.
Delete 16,000 rows, leaving every fifth ID distributed across the original heap pages. Expect DELETE 16000, then compare heap/index sizes with the baseline. Keeping live rows near the end avoids a trailing-empty-pages demonstration. A delete changes visibility, not a rewrite of the entire file; page pruning can remove some obsolete versions before explicit vacuuming.
Goal: make page-level measurements available in this database.
CREATE EXTENSION registers the installed pgstattuple functions here. Expect CREATE EXTENSION; installation does not measure or repair the table. The admin role is explicit because these functions expose physical storage details.
Goal: measure live/dead/free heap space and inspect the separate primary-key index.
pgstattuple scans physical pages rather than estimating from planner statistics. Expect 4,000 live tuples and substantial dead or free space after deletion; pruning can turn dead space into free space before this measurement. pgstatindex reports B-tree leaf density and deleted pages, not the heap’s dead-row percentage. These scans are not atomic snapshots under concurrent writes; this fixture has no concurrent writer.
Goal: remove reclaimable dead versions while retaining space for this table’s reuse.
Run ordinary VACUUM, then compare file sizes. In this scattered-row fixture, expect the heap’s main file to remain at its baseline size. Ordinary vacuum can truncate entirely empty trailing pages in other cases; it does not always preserve every byte of every relation. The total footprint can change when auxiliary maps are created.
Goal: verify what vacuum changed inside the retained files.
Expect 4,000 live tuples, zero dead tuples, and over 50% heap free space. B-tree cleanup may remove entries or mark pages reusable without shrinking its file; density/deleted-page numbers describe this index’s layout. Neither physical free space nor a dead-row count alone is a universal bloat alarm.
Goal: prove compact files still contain the same surviving IDs.
VACUUM FULL rewrites the heap and rebuilds its indexes under ACCESS EXCLUSIVE, so reads/writes wait for it. It needs room for replacement files while old files still exist; this is scheduled maintenance, not an automatic vacuum mode. Expect smaller heap and primary-key files, 4,000 surviving rows, and no ID that is not divisible by five. Restore the fixture’s normal autovacuum setting afterward. This lab documents the lock requirement but does not run another blocked client during the rewrite.