Re: age(xid) on hot standby

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: Alvaro Herrera <alvherre@commandprompt.com>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2012-01-18T19:55:46Z
Lists: pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> On mn, 2012-01-16 at 22:59 -0300, Alvaro Herrera wrote:
>> So who's going to work on a patch?  Peter, are you?  If not, we should
>> add it to the TODO list.

> Not at this very moment, but maybe in a few weeks.

BTW, it strikes me that maybe the coding should work about like this:

	if (!TransactionIdIsValid(age_reference_xid))
	{
		age_reference_xid = GetTopTransactionIdIfAny();
		if (!TransactionIdIsValid(age_reference_xid))
			age_reference_xid = ReadNewTransactionId();
	}
	... use age_reference_xid to compute result ...

and of course code somewhere to reset age_reference_xid at end of xact.

The advantage of this is

(1) same code works on master and standby

(2) calling age() no longer requires an otherwise read-only transaction
to acquire an XID.

			regards, tom lane