PostgreSQL is amazing database but has one very problematic feature which can be disastrous. This problem is called transaction ID wraparound error. We already had one problem of this kind so we set monitoring for it.

The easiest way is to monitor “age of database” – I set it using telegraf and results are stored in influxDB.

[[inputs.postgresql_extensible.query]]
sqlquery=”SELECT datname as dbname, age(datfrozenxid) as dbage FROM pg_database ORDER BY 2 DESC;”
withdbname=false
tagvalue=”db”
measurement=”postgresql_dbage”

This way you will get highest transaction ID for each database which can be easily displayed in Grafana and you can set Grafana alert when age reaches some threshold.