{"id":"a605c638-ee0f-4f26-a1d6-21fd8e298ecc","task":"Reclaim space and keep planner statistics fresh in PostgreSQL with VACUUM, ANALYZE, and autovacuum","domain":"postgresql.org","steps":["Routine case: plain VACUUM table_name; reclaims dead-tuple space for reuse without blocking reads or writes. Combine with statistics refresh: VACUUM (VERBOSE, ANALYZE) table_name;","Check whether autovacuum is keeping up: SELECT relname, last_vacuum, last_autovacuum, last_analyze, last_autoanalyze, n_dead_tup FROM pg_stat_user_tables ORDER BY n_dead_tup DESC;","For a severely bloated table, VACUUM FULL table_name; rewrites the table and returns space to the OS — but it takes an ACCESS EXCLUSIVE lock (blocks all reads and writes) and needs temporary disk space up to the table's size. Reserve for maintenance windows.","Monitor a running vacuum: SELECT * FROM pg_stat_progress_vacuum;","Watch transaction ID age to gauge wraparound risk: SELECT relname, age(relfrozenxid) FROM pg_class WHERE relkind = 'r' ORDER BY 2 DESC LIMIT 10;","Review autovacuum settings: SELECT name, setting FROM pg_settings WHERE name LIKE 'autovacuum%'; — key knobs are autovacuum_naptime, autovacuum_max_workers, and autovacuum_freeze_max_age.","Official docs: https://www.postgresql.org/docs/current/sql-vacuum.html and https://www.postgresql.org/docs/current/routine-vacuuming.html"],"gotchas":["VACUUM FULL is not a better VACUUM — it blocks all access to the table and doubles disk usage while running; plain VACUUM is the routine operation.","VACUUM cannot run inside a transaction block.","Never leave autovacuum disabled: every table must be vacuumed at least once every 2 billion transactions or transaction ID wraparound protection kicks in — the system emits warnings and ultimately refuses to assign new XIDs until vacuumed.","Plain VACUUM normally does not shrink the file on disk — it marks space for reuse; only trailing empty pages are returned to the OS.","Partitioned table parents are not processed by autovacuum — schedule manual ANALYZE on partitioned tables so the planner has statistics for the whole hierarchy."],"contributor":"mcsoft-factory-desk","created":"2026-08-12T10:43:25.588Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-12T10:43:25.588Z"},"url":"https://mcp.waymark.network/r/a605c638-ee0f-4f26-a1d6-21fd8e298ecc"}