From 73cfd502440808dee48bad6a7db7b521c3a1c885 Mon Sep 17 00:00:00 2001
From: alterego665 <824662526@qq.com>
Date: Mon, 9 Jun 2025 11:24:08 +0800
Subject: [PATCH] Add WAIT_EVENT_XACT_COMPLETE to XactLockTableWait functions
XactLockTableWait and ConditionalXactLockTableWait previously lacked a
specific wait event, making backend states less transparent. This commit
introduces WAIT_EVENT_XACT_COMPLETE, which both functions now report to
pg_stat_activity during their sleep phases, enhancing visibility.
---
src/backend/storage/lmgr/lmgr.c | 4 ++++
src/backend/utils/activity/wait_event_names.txt | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c
index 3f6bf70bd3c2..fac5e52b394d 100644
--- a/src/backend/storage/lmgr/lmgr.c
+++ b/src/backend/storage/lmgr/lmgr.c
@@ -719,7 +719,9 @@ XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid,
if (!first)
{
CHECK_FOR_INTERRUPTS();
+ pgstat_report_wait_start(WAIT_EVENT_XACT_COMPLETE);
pg_usleep(1000L);
+ pgstat_report_wait_end();
}
first = false;
xid = SubTransGetTopmostTransaction(xid);
@@ -762,7 +764,9 @@ ConditionalXactLockTableWait(TransactionId xid, bool logLockFailure)
if (!first)
{
CHECK_FOR_INTERRUPTS();
+ pgstat_report_wait_start(WAIT_EVENT_XACT_COMPLETE);
pg_usleep(1000L);
+ pgstat_report_wait_end();
}
first = false;
xid = SubTransGetTopmostTransaction(xid);
diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt
index 0be307d2ca04..421d91461b9d 100644
--- a/src/backend/utils/activity/wait_event_names.txt
+++ b/src/backend/utils/activity/wait_event_names.txt
@@ -160,6 +160,7 @@ WAL_BUFFER_INIT "Waiting on WAL buffer to be initialized."
WAL_RECEIVER_EXIT "Waiting for the WAL receiver to exit."
WAL_RECEIVER_WAIT_START "Waiting for startup process to send initial data for streaming replication."
WAL_SUMMARY_READY "Waiting for a new WAL summary to be generated."
+XACT_COMPLETE "Waiting for a transaction to complete."
XACT_GROUP_UPDATE "Waiting for the group leader to update transaction status at transaction end."
ABI_compatibility:
@@ -423,7 +424,7 @@ extend "Waiting to extend a relation."
frozenid "Waiting to update pg_database.datfrozenxid and pg_database.datminmxid."
page "Waiting to acquire a lock on a page of a relation."
tuple "Waiting to acquire a lock on a tuple."
-transactionid "Waiting for a transaction to finish."
+transactionid "Waiting to acquire a transaction ID lock; see ."
virtualxid "Waiting to acquire a virtual transaction ID lock; see ."
spectoken "Waiting to acquire a speculative insertion lock."
object "Waiting to acquire a lock on a non-relation database object."