How to Vacuum a Table in PostgreSQL

Last updated July 25, 2026 · By the SaturnSQL team

VACUUM tablename reclaims space left by dead rows; VACUUM ANALYZE also refreshes planner statistics. Autovacuum does this automatically in the background, so manual runs are mainly for after bulk deletes or updates.

VACUUM orders;
VACUUM ANALYZE orders;

Check what needs vacuuming

SELECT relname, n_dead_tup, last_vacuum, last_autovacuum
FROM pg_stat_user_tables
ORDER BY n_dead_tup DESC;

Plain VACUUM does not shrink the file on disk, it only marks space reusable. VACUUM FULL does return space to the OS but takes an exclusive lock and rewrites the whole table, blocking all reads and writes; avoid it on production unless the table is massively bloated and you have a maintenance window.

Run this in SaturnSQL

SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.

Try it free

Related PostgreSQL guides

© 2026 Panda Capital Oy Ab. All rights reserved.