VACUUM is a maintenance command that scans heap tables, removes dead tuples left by UPDATE and DELETE operations, and marks the freed pages as available for reuse. In PostgreSQL it can also update visibility maps, freeze transaction IDs to prevent wraparound, and optionally gather statistics (ANALYZE) so the query planner stays accurate. A standard VACUUM runs in the background with minimal locks, while VACUUM FULL rewrites the entire table, fully compacting it but requiring an exclusive lock. AUTOVACUUM generally handles routine cleanup, yet manual VACUUM remains essential after bulk loads, mass deletes, disabling autovacuum, or before creating critical backups. SQLite supports a different but related VACUUM that rebuilds the entire database file to defragment and shrink it.
• FULL
(keyword) - Perform a full table rewrite, reclaiming maximum space but taking an exclusive lock.• FREEZE
(keyword) - Aggressively freeze tuples to avoid transaction ID wraparound.• VERBOSE
(keyword) - Output detailed progress messages.• ANALYZE
(keyword) - Run ANALYZE on the table after vacuuming.• table_name
(identifier) - Optional table (and column list) to target; omit for all tables.- INDEX_CLEANUP { ON
- OFF }- PARALLEL integer
- Number of parallel workers.- SKIP_LOCKED
- Skip tables that cannot be locked immediately.ANALYZE, AUTOVACUUM, REINDEX, CLUSTER, CHECKPOINT
PostgreSQL 6.5 (1999); SQLite 1.0 (2000)
Autovacuum works in the background but may lag after mass deletes or when disabled. A manual VACUUM ensures space is reclaimed immediately.
VACUUM cleans pages in place with minimal locking. VACUUM FULL rewrites the table, fully reclaiming space but blocking access.
Yes. By removing bloat and updating statistics, VACUUM can improve index efficiency and planner accuracy, leading to faster queries.
PostgreSQL allows a column list only when ANALYZE is requested, letting you refresh statistics for selected columns without scanning the entire table.