The postgres documentation says:
"The age column measures the number of transactions from the cutoff XID to the current transaction's XID."
XIDs are just sequential numbers, so calculating the "age" of an XID is simple subtraction, i.e.:
age(datfrozenxid) = txid_current() - datfrozenxid
XIDs for data created during initdb
, as well as for data frozen prior to Postgres 9.4, will always report an age of 2147483647.
The full source code of the age()
function (all five lines of it) can be found here.