I am trying to understand the age function in Postgres and this is the code that I encountered – https://github.com/postgres/postgres/blob/REL_15_6/src/backend/utils/adt/xid.c#L98
I tried to understand this and these are my understandings –
The age of an a given xid
[input param(0)] of the function is
pg_current_xact_id() - xid
However can this not be negative?
x_min
for a transaction could be 1000. Post that a transaction wrap around occurred and thus the current transaction id pg_current_xact_id()
is now 100.
So if I want to calculate the age of the transaction whose x_min is 100, I would get age to be negative.
Initially in postgres, during a freeze, x_min used to be set to a default FrozenTransactionId which was 2. However that is no more the case in newer versions of postgres.
Is negative age allowed?
I am not able to test this locally and bring a transaction wrap around
qawbecrdteyf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.