Full answer
Each row records the transaction that created it (xmin). Because ids wrap around after about 4 billion values, PostgreSQL treats the 2 billion ids before the current one as the past and the rest as the future. A row whose xmin falls too far behind would suddenly look as if it came from the future and disappear, so VACUUM marks old rows as frozen, meaning visible to everyone, regardless of xmin.
What goes wrong in practice:
- A transaction or session left open for days holds back the oldest xmin, so VACUUM cannot freeze anything newer.
- An unused replication slot keeps catalog_xmin old.
- Forgotten prepared transactions (PREPARE TRANSACTION) do the same.
- Autovacuum throttled too hard on very large tables never finishes a full pass.
If the margin gets very small, PostgreSQL warns, and at about 3 million transactions remaining it refuses new transactions that assign ids until a VACUUM completes, which is an outage.
Monitoring queries (illustrative, not run here):
SELECT datname, age(datfrozenxid) FROM pg_database ORDER BY 2 DESC;
SELECT relname, age(relfrozenxid) FROM pg_class WHERE relkind = 'r' ORDER BY 2 DESC LIMIT 10;Keep idle_in_transaction_session_timeout set, drop unused slots, and make sure autovacuum has enough workers and cost budget for the largest tables. PostgreSQL 17's improved vacuum memory handling helps large tables finish faster.
Key points
- Transaction ids are 32-bit and circular
- VACUUM freezes old rows
- Long transactions and slots block freezing
- Monitor age(datfrozenxid)
- Running out forces a protective shutdown of writes
Common mistakes
- Disabling autovacuum on large tables
- Leaving replication slots unused
Follow-ups
- What does VACUUM FREEZE do?
- How do 64-bit transaction ids in other systems avoid this?
Tips
- Name the blockers