database maintenance_error ai_generated true

WARNING: oldest xmin is far in the past. HINT: Close open transactions soon to avoid wraparound problems.

ID: database/pg-vacuum-running

Also available as: JSON · Markdown
82%Fix Rate
85%Confidence
45Evidence
2023-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
16 active

Root Cause

PostgreSQL is warning about transaction ID wraparound danger. Autovacuum cannot reclaim dead tuples because long-running transactions, prepared transactions, or replication slots are holding back the oldest transaction ID. If not addressed, PostgreSQL will eventually shut down to prevent data corruption when it reaches the wraparound limit.

generic

Workarounds

  1. 88% success Identify and terminate long-running transactions blocking vacuum progress
    Run: SELECT pid, age(backend_xmin), state, query FROM pg_stat_activity WHERE backend_xmin IS NOT NULL ORDER BY age(backend_xmin) DESC LIMIT 5; Terminate blockers with SELECT pg_terminate_backend(pid). Also check pg_prepared_xacts for abandoned prepared transactions and ROLLBACK PREPARED them.
  2. 85% success Run manual VACUUM on the affected tables and tune autovacuum settings
    Run VACUUM VERBOSE on affected tables to reclaim dead tuples. Tune autovacuum: autovacuum_vacuum_cost_delay = 2ms (from default 20ms), autovacuum_max_workers = 6, autovacuum_naptime = 15s. For large tables, set per-table: ALTER TABLE t SET (autovacuum_vacuum_scale_factor = 0.01).

Dead Ends

Common approaches that don't work:

  1. Disabling autovacuum to reduce IO load on a busy production system 95% fail

    Disabling autovacuum accelerates the wraparound problem. Without vacuuming, dead tuples accumulate, table bloat grows, and the database will eventually enter single-user mode or refuse to accept writes to prevent transaction ID wraparound.

  2. Running VACUUM FULL on large tables during peak traffic 80% fail

    VACUUM FULL acquires an ACCESS EXCLUSIVE lock, blocking all reads and writes on the table for the entire duration. On large tables this can take hours, causing a full outage. Regular VACUUM (without FULL) is sufficient for wraparound prevention and allows concurrent access.

Error Chain

Leads to:
Preceded by:
Frequently confused with: