diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2012-05-11 14:36:24 +0100 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2012-05-11 14:36:24 +0100 |
commit | b06679e01244d33304b71a6a44c7cc86173617b3 (patch) | |
tree | e53c3c2f8f2649a408e25262f2674717ea3e4b86 /src/backend/access/transam/xact.c | |
parent | 3652d72dd45b3ef2ca5e83e8cbd09f78696ad4c4 (diff) | |
download | postgresql-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.c | 22 |
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. |