aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xact.c
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2012-05-11 14:36:24 +0100
committerSimon Riggs <simon@2ndQuadrant.com>2012-05-11 14:36:24 +0100
commitb06679e01244d33304b71a6a44c7cc86173617b3 (patch)
treee53c3c2f8f2649a408e25262f2674717ea3e4b86 /src/backend/access/transam/xact.c
parent3652d72dd45b3ef2ca5e83e8cbd09f78696ad4c4 (diff)
downloadpostgresql-b06679e01244d33304b71a6a44c7cc86173617b3.tar.gz
postgresql-b06679e01244d33304b71a6a44c7cc86173617b3.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 7f412b10d75..1654a0e5c73 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -392,6 +392,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.