A team deletes months of old test records from a PostgreSQL table. The query finishes, but the disk graph hardly moves. Someone suggests running the strongest cleanup command immediately. Before doing that, it helps to know what PostgreSQL is preserving for concurrent transactions and what “free space” means at each layer.
PostgreSQL vacuuming is routine maintenance that helps make space from obsolete row versions reusable and performs other work needed for database health. Standard VACUUM generally makes space available for reuse within the table; it does not normally return all of it to the operating system. The PostgreSQL routine-maintenance guide explains the distinction and the separate costs of VACUUM FULL.
A flat disk graph after a deletion is therefore not enough to diagnose a failed maintenance job. It is a reason to ask whether the table has reusable space, whether old row versions are still needed, and whether the storage system is under actual pressure. The answer should guide a measured plan, not a reflexive table rewrite.
Why an update leaves an older version
PostgreSQL uses multiversion concurrency control, often called MVCC, to let transactions work with appropriate versions of data. An update or delete does not necessarily make an earlier row version immediately removable. Another transaction may still need to see it under its snapshot. Once a row version is no longer relevant to any transaction, its space can eventually become available for reuse through vacuuming.
Consider a fictional reservations table. A row says a booking is pending. One transaction begins a query while another changes the booking to confirmed. The database has to manage visibility according to the isolation and timing of those transactions; the old value cannot simply be discarded at an arbitrary instant. Our guide to transaction isolation explains why different transactions can observe data at different moments.
This is a conceptual illustration, not a precise description of every internal tuple state. What matters operationally is that repeated updates and deletes can leave old versions that later need maintenance. A table with many changes can have very different maintenance needs from a similarly sized table whose rows rarely change.
Reusable is not the same as returned to the operating system
Standard vacuum removes dead row versions where it can and marks space for future reuse. If new rows or updates later need room, PostgreSQL may use space already inside the table rather than growing the file by the same amount. That internal capacity is useful even when a filesystem dashboard still shows the table occupying roughly the same number of bytes.
Imagine a table file occupying 100 GB. After a large deletion and appropriate maintenance, suppose an investigation estimates that 20 GB within it can be reused. The file may still occupy close to 100 GB at the filesystem level, while later table activity can use some of that internal room. This is a simplified example: real free space can be distributed across pages, and an estimate is not a promise that every future write fits without growth.
The PostgreSQL documentation notes a limited exception where entirely free pages at the end of a table may be returned if the required lock can be obtained. Do not turn that exception into an expectation that ordinary vacuum will shrink every table. Conversely, do not call all retained file space wasted without considering the workload that is likely to refill it.
Autovacuum has a job, not a magic clock
PostgreSQL includes an autovacuum daemon that can schedule vacuum and analyze work in response to database activity. For many installations it handles routine maintenance, though configuration and workload matter. A large table, a sudden burst of changes, slow storage or competing work can create a gap between the maintenance needed and what has completed.
Ask whether autovacuum is enabled for the relevant database and table, when the table was last maintained, how much change has occurred and whether maintenance can make progress. The answer may involve table-specific settings and the actual version in use. A timestamp alone is not a complete health check; a recently started job can still be running or unable to clear versions needed by an old transaction.
Do not disable autovacuum merely to make an operation appear faster. PostgreSQL’s documentation cautions against turning it off completely in most workloads. If maintenance is consuming resources, investigate its cause and configuration with an administrator who understands the workload and recovery plan. Changing a threshold without measuring the result can trade today’s latency for a larger problem later.
Old transactions can hold the door open
A long-running transaction may retain a snapshot that keeps certain old row versions potentially visible. Those versions cannot be reclaimed as if no reader might need them. An idle session left inside a transaction can therefore affect cleanup even when the application that opened it appears quiet.
Suppose a reporting job starts, opens a transaction and then waits for an external service for hours. Meanwhile, a busy table receives many updates. Vacuum may run, but some old versions may remain necessary until the transaction ends. The specific result depends on isolation, snapshots and the database state. The point is to inspect transaction age and workload behavior before assuming the vacuum process is simply “not working.”
Ending a transaction can interrupt a real report or roll back work. Identify its owner and purpose, review current activity and follow the organization’s normal incident procedure before taking action. A diagnostic observation is not permission to terminate an unknown session. Test application changes, such as shorter transactions or different batching, against the consistency the business requires.
Statistics, visibility and transaction IDs
Vacuuming is not only about reclaiming space. PostgreSQL documents maintenance of the visibility map and protection against transaction-ID and multitransaction-ID wraparound among its reasons for regular vacuum work. Statistics used by the query planner are maintained through ANALYZE, which can be run with vacuum or separately and is also managed by autovacuum under its rules.
These functions answer different questions. Space reuse concerns old row versions; planner statistics help the database estimate data distributions; visibility information can support certain index-only scans. Running one maintenance action is not proof that every query has an appropriate index or that every estimate is accurate. Check the actual plan, table activity and statistics when a query changes behavior.
Wraparound protection is a particularly poor place for guesswork. PostgreSQL tracks transaction ages and requires preventive maintenance. If an alert indicates an approaching limit, consult the current documentation and the responsible database operator promptly. The exact response depends on version, configuration and state; a casual instruction to delete files or reset counters is not a recovery plan.
Why VACUUM FULL deserves a separate decision
VACUUM FULL rewrites the table and can return more space to the operating system. It also requires an exclusive lock on the table, can take substantial time and needs additional disk space while the new copy is built. Those characteristics make it materially different from the ordinary maintenance most teams expect to run alongside normal activity.
Suppose a 100 GB table has shrunk in actual use and the team wants to return filesystem capacity. A full rewrite may sound attractive, but a production application that needs the table can be blocked while the exclusive lock is held. The operation also needs headroom for the new copy and related work. Measure the table and indexes, verify available capacity, estimate the maintenance window and test the procedure on a representative environment before selecting a method.
The database may grow again immediately if the same workload resumes. In that case, reducing the file to its smallest size can be temporary while the disruption is real. An operator should compare alternatives and their lock, space and recovery implications using current PostgreSQL documentation and the organization’s own operating constraints.
Investigate the change in context
Start with the exact table, database version and time window. Record table and index sizes, update and delete activity, maintenance history, transaction age and current storage headroom. Separate observed values from estimates: a reported table size, filesystem free space and estimated dead-row count are different measurements.
Then ask what changed. Did a new batch job update nearly every row? Did a report leave transactions open? Has the table’s update rate exceeded its normal maintenance capacity? Did a query slow because of stale statistics, a changed plan, an index issue or resource contention? Our guide to database indexes covers one related source of performance tradeoffs; it does not substitute for inspecting the actual query.
Finally, decide who owns the intervention, what can be tested safely and how success will be measured. A stable table size, fewer old transactions, successful maintenance and a query that performs adequately may be better evidence of health than a smaller file alone. Vacuuming works best as part of a maintenance practice, not as an emergency button pressed whenever a disk chart refuses to fall.
Explore Infinite Upside
For Vijay Sheth’s personal accounts, read Infinite Upside: Building Wealth With Room to Live, published by Sheth Capital, Inc.
Explore a related guide
What Does Database Transaction Isolation Change?