如何在 PostgreSQL 中计算年龄(datfrozenxid)?
How is age(datfrozenxid) calculated in PostgreSQL?
postgres 文档说:
"The age column measures the number of transactions from the cutoff
XID to the current transaction's XID."
XID 只是序号,因此计算 XID 的 "age" 是简单的减法,即:
age(datfrozenxid) = txid_current() - datfrozenxid
在 initdb
期间创建的数据的 XID,以及在 Postgres 9.4 之前冻结的数据,将始终报告 2147483647 的年龄。
可以找到 age()
函数的完整源代码(全部五行)here。
postgres 文档说:
"The age column measures the number of transactions from the cutoff XID to the current transaction's XID."
XID 只是序号,因此计算 XID 的 "age" 是简单的减法,即:
age(datfrozenxid) = txid_current() - datfrozenxid
在 initdb
期间创建的数据的 XID,以及在 Postgres 9.4 之前冻结的数据,将始终报告 2147483647 的年龄。
可以找到 age()
函数的完整源代码(全部五行)here。