aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/xid.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2014-09-10 17:13:04 -0400
committerBruce Momjian <bruce@momjian.us>2014-09-10 17:13:04 -0400
commit36ad1a87a368d837d5c2260b2fd2ff83e976425a (patch)
treeb951f5f04b2f8f46f3d5947e092590b7f248d07d /src/backend/utils/adt/xid.c
parent84aa8ba128a08e6fdebb2497c7a79ebf18093e12 (diff)
downloadpostgresql-36ad1a87a368d837d5c2260b2fd2ff83e976425a.tar.gz
postgresql-36ad1a87a368d837d5c2260b2fd2ff83e976425a.zip
Implement mxid_age() to compute multi-xid age
Report by Josh Berkus
Diffstat (limited to 'src/backend/utils/adt/xid.c')
-rw-r--r--src/backend/utils/adt/xid.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/utils/adt/xid.c b/src/backend/utils/adt/xid.c
index 602a9e5d6f4..ecb3cf55dd1 100644
--- a/src/backend/utils/adt/xid.c
+++ b/src/backend/utils/adt/xid.c
@@ -16,6 +16,7 @@
#include <limits.h>
+#include "access/multixact.h"
#include "access/transam.h"
#include "access/xact.h"
#include "libpq/pqformat.h"
@@ -103,6 +104,21 @@ xid_age(PG_FUNCTION_ARGS)
}
/*
+ * mxid_age - compute age of a multi XID (relative to latest stable mxid)
+ */
+Datum
+mxid_age(PG_FUNCTION_ARGS)
+{
+ TransactionId xid = PG_GETARG_TRANSACTIONID(0);
+ MultiXactId now = ReadNextMultiXactId();
+
+ if (!MultiXactIdIsValid(xid))
+ PG_RETURN_INT32(INT_MAX);
+
+ PG_RETURN_INT32((int32) (now - xid));
+}
+
+/*
* xidComparator
* qsort comparison function for XIDs
*