src/backend/utils/adt/xid8funcs.c
Datum
pg_xact_status(PG_FUNCTION_ARGS)
{
	const char *status;
	FullTransactionId fxid = PG_GETARG_FULLTRANSACTIONID(0);
	TransactionId xid;

	/*
	 * We must protect against concurrent truncation of clog entries to avoid
	 * an I/O error on SLRU lookup.
	 */
	LWLockAcquire(XactTruncationLock, LW_SHARED);
	if (TransactionIdInRecentPast(fxid, &xid))
	{
		Assert(TransactionIdIsValid(xid));

		if (TransactionIdIsCurrentTransactionId(xid))
			status = "in progress";
		else if (TransactionIdDidCommit(xid))
			status = "committed";
		else if (TransactionIdDidAbort(xid))
			status = "aborted";
		else
		{
			/*
			 * The xact is not marked as either committed or aborted in clog.
			 *
			 * It could be a transaction that ended without updating clog or
			 * writing an abort record due to a crash. We can safely assume
			 * it's aborted if it isn't committed and is older than our
			 * snapshot xmin.
			 *
			 * Otherwise it must be in-progress (or have been at the time we
			 * checked commit/abort status).
			 */
			if (TransactionIdPrecedes(xid, GetActiveSnapshot()->xmin))
				status = "aborted";
			else
				status = "in progress";
		}
	}
	else
	{
		status = NULL;
	}
	LWLockRelease(XactTruncationLock);

	if (status == NULL)
		PG_RETURN_NULL();
	else
		PG_RETURN_TEXT_P(cstring_to_text(status));
}
/*
 * Report the status of a recent transaction ID, or null for wrapped,
 * truncated away or otherwise too old XIDs.
 *
 * The passed epoch-qualified xid is treated as a normal xid, not a
 * multixact id.
 *
 * If it points to a committed subxact the result is the subxact status even
 * though the parent xact may still be in progress or may have aborted.
 */
Report the status of a recent transaction ID, or null for wrapped,
truncated away or otherwise too old XIDs.

The passed epoch-qualified xid is treated as a normal xid, not a
multixact id.

If it points to a committed subxact the result is the subxact status even
though the parent xact may still be in progress or may have aborted.
Report the status of a recent transaction ID or null for wrapped truncated away or otherwise too old XIDs . The passed epoch - qualified xid is treated as a normal xid not a multixact id . If it points to a committed subxact the result is the subxact status even though the parent xact may still be in progress or may have aborted .
Datum
pg_xact_status(PG_FUNCTION_ARGS)
{
	const char *status;
	FullTransactionId fxid = PG_GETARG_FULLTRANSACTIONID(0);
	TransactionId xid;
	LWLockAcquire(XactTruncationLock, LW_SHARED);
	if (TransactionIdInRecentPast(fxid, &xid))
	{
		Assert(TransactionIdIsValid(xid));
		if (TransactionIdIsCurrentTransactionId(xid))
			status = "in progress";
		else if (TransactionIdDidCommit(xid))
			status = "committed";
		else if (TransactionIdDidAbort(xid))
			status = "aborted";
		else
		{
			if (TransactionIdPrecedes(xid, GetActiveSnapshot()->xmin))
				status = "aborted";
			else
				status = "in progress";
		}
	}
	else
	{
		status = NULL;
	}
	LWLockRelease(XactTruncationLock);
	if (status == NULL)
		PG_RETURN_NULL();
	else
		PG_RETURN_TEXT_P(cstring_to_text(status));
}
Datum pg_xact_status ( PG_FUNCTION_ARGS ) { const char * status ; FullTransactionId fxid = PG_GETARG_FULLTRANSACTIONID ( 0 ) ; TransactionId xid ; LWLockAcquire ( XactTruncationLock , LW_SHARED ) ; if ( TransactionIdInRecentPast ( fxid , & xid ) ) { Assert ( TransactionIdIsValid ( xid ) ) ; if ( TransactionIdIsCurrentTransactionId ( xid ) ) status = " " ; else if ( TransactionIdDidCommit ( xid ) ) status = " " ; else if ( TransactionIdDidAbort ( xid ) ) status = " " ; else { if ( TransactionIdPrecedes ( xid , GetActiveSnapshot ( ) -> xmin ) ) status = " " ; else status = " " ; } } else { status = NULL ; } LWLockRelease ( XactTruncationLock ) ; if ( status == NULL ) PG_RETURN_NULL ( ) ; else PG_RETURN_TEXT_P ( cstring_to_text ( status ) ) ; }
Report the status of a recent transaction ID, or null for wrapped,
 truncated away or otherwise too old XIDs.
Report the status of a recent transaction ID or null for wrapped truncated away or otherwise too old XIDs .
/*
	 * We must protect against concurrent truncation of clog entries to avoid
	 * an I/O error on SLRU lookup.
	 */ /*
			 * The xact is not marked as either committed or aborted in clog.
			 *
			 * It could be a transaction that ended without updating clog or
			 * writing an abort record due to a crash. We can safely assume
			 * it's aborted if it isn't committed and is older than our
			 * snapshot xmin.
			 *
			 * Otherwise it must be in-progress (or have been at the time we
			 * checked commit/abort status).
			 */