/* * xideq - are two xids equal? */ Datum xideq(PG_FUNCTION_ARGS) { TransactionId xid1 = PG_GETARG_TRANSACTIONID(0); TransactionId xid2 = PG_GETARG_TRANSACTIONID(1); PG_RETURN_BOOL(TransactionIdEquals(xid1, xid2)); }
/* * xidsend - converts xid to binary format */ Datum xidsend(PG_FUNCTION_ARGS) { TransactionId arg1 = PG_GETARG_TRANSACTIONID(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint(&buf, arg1, sizeof(arg1)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
/* * 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)); }
/* * 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 = GetTopTransactionId(); /* Permanent XIDs are always infinitely old */ if (!TransactionIdIsNormal(xid)) PG_RETURN_INT32(INT_MAX); PG_RETURN_INT32((int32) (now - xid)); }
Datum xidout(PG_FUNCTION_ARGS) { TransactionId transactionId = PG_GETARG_TRANSACTIONID(0); /* maximum 32 bit unsigned integer representation takes 10 chars */ char *str = palloc(11); snprintf(str, 11, "%lu", (unsigned long) transactionId); PG_RETURN_CSTRING(str); }