dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/postgresql/#7
Script #7
postgresql
Monitoringread-onlyMin Version: 9.x

PostgreSQL Transaction ID Wraparound Risk Check

Shows XID age per database and how close it is to the wraparound limit. A reliable alert source to catch a critical outage early.

#xid#wraparound#freeze#critical
postgresql · sql
SELECT datname,
       age(datfrozenxid) AS xid_age,
       round(100.0 * age(datfrozenxid) / 2147483647, 2) AS pct_to_wraparound
FROM pg_database
ORDER BY xid_age DESC;
Operational Notes & Remediation Guidance

Aggressive vacuum triggers as transaction age approaches `autovacuum_freeze_max_age` (default 200M). Alert when utilization exceeds 50%.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 9.x).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.