A high-write table is growing, and its dead-tuple estimate keeps climbing even though autovacuum appears active.
This week, compare dead-tuple trends with vacuum history, long transactions, and replication state before changing settings. Do not use VACUUM FULL as the default fix: ordinary VACUUM usually makes space reusable inside the database rather than shrinking the file on disk.
This guide is for DBAs investigating bloat in heavily updated or deleted tables.
Backend engineers maintaining a self-hosted PostgreSQL database can use it to build a safer investigation and tuning process.
SaaS technical leads can use the checks to assess maintenance capacity, storage layout, and data protection needs.
Last updated October 24, 2026; version information and behavior were checked against the PostgreSQL 18 release notes and PostgreSQL 18 maintenance documentation. The official release page lists the PostgreSQL 18.6 series.
Separate dead-tuple buildup from disk space that can be reused
An UPDATE creates a new row version when PostgreSQL changes a row. A DELETE marks a row version as no longer current. Vacuum’s job is to make row versions that are no longer visible to any transaction available for reuse. That work does not necessarily shrink the relation file that your operating system sees. The distinction is central to PostgreSQL 18 table bloat troubleshooting. See the PostgreSQL documentation on routine vacuuming.
Start by comparing three observations for the same table:
- Dead-tuple estimates: are they increasing, stable, or falling?
- Maintenance history: when did autovacuum last run, and has it been running repeatedly?
- Relation and disk usage: is storage still increasing over time, or does the table appear large but stable?
Use the table statistics view to inspect the first two:
SELECT schemaname,
relname,
n_live_tup,
n_dead_tup,
n_mod_since_analyze,
last_autovacuum,
autovacuum_count,
last_autoanalyze
FROM pg_stat_user_tables
WHERE relname = 'target_table';
These values are estimates and counters, not a direct measurement of reclaimable bytes. Compare them under consistent observation conditions. Check whether statistics were reset, and avoid comparing readings taken from a transaction that may be holding an old statistics snapshot. PostgreSQL documents the meaning and limitations of these fields in its statistics views reference.
A table can keep a large on-disk footprint after cleanup because PostgreSQL can reuse free space for later rows. That is different from a table whose dead-tuple estimate keeps rising while writes continue. Treat those as separate findings: the first may need no compaction; the second needs an explanation for why cleanup is not keeping up.
Find out whether autovacuum is late, active, or constrained
Autovacuum is triggered using table activity and configuration thresholds. The trigger calculation uses a threshold plus a scale factor multiplied by the table’s estimated row count; table-level settings can override global behavior. The formula and configurable parameters are documented in the PostgreSQL 18 autovacuum settings reference.
Inspect the settings that apply before tuning them:
SHOW autovacuum;
SHOW autovacuum_vacuum_threshold;
SHOW autovacuum_vacuum_scale_factor;
SHOW autovacuum_max_workers;
SHOW autovacuum_vacuum_cost_limit;
Then check for table-specific options:
SELECT relname, reloptions
FROM pg_class
WHERE oid = 'public.target_table'::regclass;
If no table-level value appears, the relation generally uses the corresponding system setting. Do not assume a global setting describes every table: a high-write table may have its own options, and its size affects when a scale-factor threshold is reached.
When you suspect vacuum is running now, inspect PostgreSQL’s progress view:
SELECT a.pid,
a.datname,
p.relid::regclass AS relation,
p.phase,
p.heap_blks_total,
p.heap_blks_scanned,
p.heap_blks_vacuumed,
p.index_vacuum_count
FROM pg_stat_progress_vacuum AS p
JOIN pg_stat_activity AS a USING (pid);
The phase and block counters help distinguish a vacuum that has not started from one in progress. Interpret them as a changing snapshot, not as a guaranteed completion-time estimate. PostgreSQL documents the available fields in its vacuum progress reporting reference.
Also inspect your PostgreSQL logs for autovacuum messages. A quiet log does not prove a table is healthy; logging depends on configuration. Conversely, a vacuum that has started may still be unable to remove row versions if an older snapshot is holding them back. Track the table’s statistics and log messages alongside progress, rather than using a single observation as the diagnosis.
Check old transactions and replication state before intervening
A long-running transaction can retain an old snapshot. Row versions that might still be visible to that snapshot cannot yet be removed, even if autovacuum has reached the table. Begin with active transactions and their age:
SELECT pid,
usename,
state,
xact_start,
backend_xmin,
wait_event_type,
wait_event,
query
FROM pg_stat_activity
WHERE xact_start IS NOT NULL
ORDER BY xact_start;
Look for transactions that have remained open while the affected table’s dead-tuple estimate rises. Check application ownership and transaction purpose before taking action. An idle session in a transaction can matter as much as a query that is actively consuming CPU: its snapshot may still affect which row versions can be removed.
Replication slots can also retain information needed by consumers. Inspect their state rather than assuming a slot is obsolete:
SELECT slot_name,
slot_type,
active,
xmin,
catalog_xmin,
restart_lsn
FROM pg_replication_slots;
The PostgreSQL replication slot view documentation defines these fields. A slot that appears inactive may belong to a consumer that is temporarily offline or needed for recovery. Confirm ownership, downstream dependencies, and the consequences of changing its state before doing anything destructive.
Do not terminate a production transaction or drop a replication slot just to make a vacuum finish. First identify the application or consumer, confirm what will be interrupted, and agree on a recovery path.
Choose a response based on what the evidence shows
Use the following decision branches. They keep routine cleanup separate from file compaction and avoid turning every increase in disk use into a rewrite operation.
- If dead tuples are stable or falling and the file is not continuing to grow: keep monitoring. Ordinary vacuum may already have made space available for reuse.
- If dead tuples keep rising and autovacuum has not reached the relation: check the trigger thresholds, table overrides, worker availability, and the table’s write pattern. Adjust one relevant setting at a time.
- If vacuum is active but cannot remove old versions: investigate old transactions and replication state before changing worker or cost settings.
- If cleanup is working but the operating-system file remains large: decide whether internal reuse is sufficient. If it is, do not rewrite merely to reduce the displayed file size.
- If you need to reclaim file space and can plan for the operational impact: compare a full rewrite, an appropriate online reorganization method, or a retention design that removes eligible old partitions.
| Option | What it addresses | Main trade-off |
|---|---|---|
Ordinary VACUUM |
Makes eligible space available for reuse | Usually does not shrink the relation file to the operating system |
VACUUM FULL |
Rewrites a relation to compact it | Requires an ACCESS EXCLUSIVE lock and extra disk space for the rewrite; confirm these constraints in the PostgreSQL routine maintenance documentation |
| Online reorganization tool | May offer a different locking profile | Verify tool compatibility, prerequisites, replication behavior, and temporary storage needs in that tool’s own documentation |
| Partition retention | Removes data that is no longer needed when the schema and retention policy support it | Requires suitable partitioning and a tested retention process; validate the design against your schema and retention requirements |
Before a rewrite, confirm free space for both the existing data and the replacement work, and check whether dependent indexes, replicas, and application queries will be affected. Do not estimate an expected reclaim percentage or maintenance duration from another workload; measure your own table and rehearse the operation in a representative environment.
FAQ: common PostgreSQL vacuum symptoms
Why can a table keep growing when autovacuum is running?
Autovacuum can run normally while a table still grows if its cleanup rate does not keep pace with writes, if long-running transactions or replication state retain old row versions, or if freed space remains inside the table file for reuse. Compare dead-tuple trends, vacuum history, transaction age, and relation size before treating file size alone as proof of failure.
What should I check when PostgreSQL dead tuples keep increasing?
First compare the same table’s dead-tuple estimate across observations and confirm that statistics have not been reset or read from a stale transaction snapshot. Then inspect modification counts, the last autovacuum, active vacuum progress, long transactions, and replication slots. A rising estimate points to a cleanup or visibility problem, but it does not by itself identify the cause.
Why did the database file stay the same size after VACUUM?
Ordinary VACUUM generally makes space inside a relation available for reuse; it does not promise to return that space to the operating system. The table file can therefore remain the same size even after dead tuples are removed. Consider a rewrite operation only when you need to compact the file and can accept its locking, extra-space, and operational risks.
Can a long-running transaction prevent autovacuum from cleaning a table?
Yes. A transaction holding an old snapshot can keep row versions potentially visible, so vacuum cannot remove them yet. Check transaction age and backend state, then identify the owner and business impact before intervening. Do not terminate a production transaction or remove a replication slot simply because it appears old; confirm its purpose and recovery implications first.
Tune one table at a time and validate the result
Do not copy a single “best” autovacuum value across every relation. Write volume, row count, update patterns, transaction duration, and index maintenance all affect whether a setting is suitable. Use the global settings and table-level options as control points, then make a small, reversible change for the affected table.
A table-level setting follows this pattern:
ALTER TABLE public.target_table
SET (autovacuum_vacuum_scale_factor = <value_based_on_observed_workload>);
Replace the placeholder with a measured value chosen for your workload; it is not a literal SQL value. Check the PostgreSQL 18 autovacuum configuration documentation for valid options and exact behavior. If you adjust worker or cost settings globally, document the prior values and expected side effects before applying the change.
Validate using the same observations you used to diagnose the problem:
- Compare
n_dead_tup, modification counts, and vacuum history for the same relation. - Check whether vacuum reaches and completes the table, using the progress view and relevant log entries.
- Confirm that dead-tuple estimates stop trending upward under a comparable write pattern.
- Watch for maintenance competing with foreground queries or other database work.
- Keep the previous setting available so you can revert if the observed behavior worsens.
This is a controlled operational test, not a promise that a parameter change will reduce file size. If the actual problem is an old transaction, a tuning change can leave the root cause untouched. If the table has already been cleaned and space is reusable, a rewrite may add risk without fixing an active fault.
Include storage and recovery in the database plan
Table maintenance consumes I/O and can require temporary working space, especially when you choose a rewrite rather than ordinary vacuum. When planning a self-hosted database server, compare the sustained write pattern, data growth, maintenance windows, and free-space requirements with the storage and memory resources you can actually select. Use the VPSAMD hardware specification sheet to verify available resources before sizing a database host; do not assume a particular disk layout or configuration will cure bloat.
An independent server does not protect you from accidental deletion, storage failure, bad migrations, or a failed maintenance operation. If your selected server has no hardware RAID, plan software RAID or database replication where appropriate. Neither replaces a backup stored outside the database host. Follow PostgreSQL’s backup and restore guidance, and test that you can restore the data and required transaction history before relying on a backup plan.
If your current shared VPS or cloud instance is meeting the workload, keep it until measurements show a constraint. Before changing, check whether CPU contention, storage performance limits or billing, and restricted control over disk layout are actually affecting your database; these vary by service and plan. For sustained database work that needs dedicated hardware resources, VPSAMD’s AMD bare-metal servers may be a better fit than a shared instance—but the hardware will not remove table bloat or replace vacuum, replication, and off-host backups. Compare the current options on the VPSAMD plans page, then choose only after your table statistics and recovery plan support the move.
Frequently asked questions
Why can a PostgreSQL table keep growing when autovacuum is running?
Autovacuum can run normally while a table still grows if its cleanup rate does not keep pace with writes, if long-running transactions or replication state retain old row versions, or if the freed space remains inside the table file for reuse. Compare dead-tuple trends, vacuum history, transaction age, and relation size before treating file size alone as proof of failure.
What should I check when PostgreSQL dead tuples keep increasing?
First compare the same table’s dead-tuple estimate across observations and confirm that statistics have not been reset or read from a stale transaction snapshot. Then inspect modification counts, the last autovacuum, active vacuum progress, long transactions, and replication slots. A rising estimate points to a cleanup or visibility problem, but it does not by itself identify the cause.
Why did the database file stay the same size after VACUUM?
Ordinary VACUUM generally makes space inside a relation available for reuse; it does not promise to return that space to the operating system. The table file can therefore remain the same size even after dead tuples are removed. Consider a rewrite operation only when you need to compact the file and can accept its locking, extra-space, and operational risks.
Can a long-running transaction prevent autovacuum from cleaning a table?
Yes. A transaction holding an old snapshot can keep row versions potentially visible, so vacuum cannot remove them yet. Check transaction age and backend state, then identify the owner and business impact before intervening. Do not terminate a production transaction or remove a replication slot simply because it appears old; confirm its purpose and recovery implications first.
EPYC 7543P Dedicated Physical Server
From $442.9/mo
