From d9e1ea4de8c96c913bd979c1209258157a4605d9 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 31 May 2012 11:12:33 -0400
Subject: [PATCH] Revert back-branch changes in behavior of age(xid).

Per discussion, it does not seem like a good idea to change the behavior of
age(xid) in a minor release, even though the old definition causes the
function to fail on hot standby slaves.  Therefore, revert commit
5829387381d2e4edf84652bb5a712f6185860670 and follow-on commits in the back
branches only.
---
 src/backend/access/transam/xact.c | 24 ------------------------
 src/backend/utils/adt/xid.c       |  4 ++--
 src/include/access/xact.h         |  1 -
 3 files changed, 2 insertions(+), 27 deletions(-)

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 511e17c2e4..33431585d8 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -386,30 +386,6 @@ GetCurrentTransactionIdIfAny(void)
 	return CurrentTransactionState->transactionId;
 }
 
-/*
- *	GetStableLatestTransactionId
- *
- * Get the XID once and then return same value for rest of transaction.
- * Acts as a useful reference point for maintenance tasks.
- */
-TransactionId
-GetStableLatestTransactionId(void)
-{
-	static LocalTransactionId lxid = InvalidLocalTransactionId;
-	static TransactionId stablexid = InvalidTransactionId;
-
-	if (lxid != MyProc->lxid)
-	{
-		lxid = MyProc->lxid;
-		stablexid = GetTopTransactionIdIfAny();
-		if (!TransactionIdIsValid(stablexid))
-			stablexid = ReadNewTransactionId();
-	}
-
-	Assert(TransactionIdIsValid(stablexid));
-
-	return stablexid;
-}
 
 /*
  * AssignTransactionId
diff --git a/src/backend/utils/adt/xid.c b/src/backend/utils/adt/xid.c
index f370c7f162..fcde92cb8a 100644
--- a/src/backend/utils/adt/xid.c
+++ b/src/backend/utils/adt/xid.c
@@ -87,13 +87,13 @@ xideq(PG_FUNCTION_ARGS)
 }
 
 /*
- *		xid_age			- compute age of an XID (relative to latest stable xid)
+ *		xid_age			- compute age of an XID (relative to current xact)
  */
 Datum
 xid_age(PG_FUNCTION_ARGS)
 {
 	TransactionId xid = PG_GETARG_TRANSACTIONID(0);
-	TransactionId now = GetStableLatestTransactionId();
+	TransactionId now = GetTopTransactionId();
 
 	/* Permanent XIDs are always infinitely old */
 	if (!TransactionIdIsNormal(xid))
diff --git a/src/include/access/xact.h b/src/include/access/xact.h
index daa42d9243..12ec693f44 100644
--- a/src/include/access/xact.h
+++ b/src/include/access/xact.h
@@ -177,7 +177,6 @@ extern TransactionId GetTopTransactionId(void);
 extern TransactionId GetTopTransactionIdIfAny(void);
 extern TransactionId GetCurrentTransactionId(void);
 extern TransactionId GetCurrentTransactionIdIfAny(void);
-extern TransactionId GetStableLatestTransactionId(void);
 extern SubTransactionId GetCurrentSubTransactionId(void);
 extern CommandId GetCurrentCommandId(bool used);
 extern TimestampTz GetCurrentTransactionStartTimestamp(void);
-- 
2.49.0