aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xact.c
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2012-05-11 14:38:11 +0100
committerSimon Riggs <simon@2ndQuadrant.com>2012-05-11 14:38:11 +0100
commit1a4bc2db6cb80a6e52aed8f5a68b895231653d6c (patch)
tree2882f193163ac3fac7c582f1bb9fcc1498219d88 /src/backend/access/transam/xact.c
parent153b1dbaa0b94143041ab1e0cf249a02380f0acf (diff)
downloadpostgresql-1a4bc2db6cb80a6e52aed8f5a68b895231653d6c.tar.gz
postgresql-1a4bc2db6cb80a6e52aed8f5a68b895231653d6c.zip
Ensure age() returns a stable value rather than the latest value
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r--src/backend/access/transam/xact.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 901fff059a1..be4905181e0 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -394,6 +394,28 @@ GetCurrentTransactionIdIfAny(void)
/*
+ * GetStableLatestTransactionIdIfAny
+ *
+ * Get the latest 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 ||
+ !TransactionIdIsValid(stablexid))
+ {
+ lxid = MyProc->lxid;
+ stablexid = ReadNewTransactionId();
+ }
+
+ return stablexid;
+}
+
+/*
* AssignTransactionId
*
* Assigns a new permanent XID to the given TransactionState.