Three maintenance jobs, three observations
The fixture keeps every tenth inserted row, spreading 10,000 survivors across the heap. Automatic maintenance is disabled only on vac_demo so the manual baseline stays observable.
Before vacuuming, save heap and total bytes and inspect pg_visibility_map_summary. Afterward, compare the same values. The heap stays the same size in this scattered-survivor fixture; auxiliary forks can change, and ordinary VACUUM can truncate wholly empty tail pages in other tables.
Read VACUUM VERBOSE: pages reports scan/removal work; tuples distinguishes removed, remaining and not-yet-removable versions; visibility map reports page marking; buffer usage describes shared-buffer activity; WAL usage reports generated records and bytes. Rates and buffer counts vary. A shared-buffer miss is not proof of a physical disk read.
ANALYZE populates column statistics: pg_stats.n_distinct = -1 describes unique IDs, while 1 describes the constant payload. It does a different job from dead-version removal. The map's positive all-visible count is page-level evidence, not a row count or a guaranteed index-only plan.
Did you know? VACUUM has an escape hatch for empty pages at a table's end: ordinary vacuum can sometimes return those pages to the OS without a full rewrite. Routine vacuuming.
Key concepts
Visibility Map
A compact, one-bit-per-page (plus one bit for all-frozen) bitmap PostgreSQL maintains alongside every table, tracking whether every tuple on a page is visible to all current and future transactions. An index-only scan can skip visiting the heap entirely for an all-visible page, and VACUUM itself uses it to skip pages that need no cleaning — which is why a table that is vacuumed often stays cheap to vacuum again.
pg_statistic vs pg_stat_user_tables
These sound similar and do completely different jobs. pg_stat_user_tables (used throughout this course) reports activity counters — scans, dead tuples, timestamps. pg_statistic, populated by ANALYZE and normally read through the pg_stats view, holds the query planner's actual knowledge of data distribution: how many distinct values a column has, its most common values, and histogram boundaries used to estimate selectivity.