Add new wait event to XactLockTableWait

From: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, Kevin K Biju <kevinkbiju(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Add new wait event to XactLockTableWait
Date: 2025-06-08 14:30:45
Message-ID: CABPTF7WZODAVPFxtn9ygA9d6zckkJbFG=SUtHdvk7ca=UTzSFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

Currently, when XactLockTableWait() and ConditionalXactLockTableWait()
sleep waiting for transactions to complete, they don't report any
specific wait event to the statistics system. This means that backends
stuck in these waits show up in pg_stat_activity with NULL
wait_event_type and wait_event columns, making it difficult for users
to understand what's actually happening.

This is more problematic in logical replication scenarios where these
waits can be very long - for example, when creating a logical
replication slot on a busy system. Without a specific wait event, it's
hard to distinguish legitimate wait from other issues.

Based on suggestions from Fujii and Kevin [1], the patch introduces
WAIT_EVENT_XACT_DONE ("Waiting for a transaction to commit or abort")
and instructs both functions to report this event during their
pg_usleep() calls With patch applied, when backends are waiting in
these functions, pg_stat_activity will show what they're waiting for.

Head:
postgres=# SELECT pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
postgres=# SELECT pid,wait_event_type,wait_event,state,query FROM
pg_stat_activity WHERE pid=5074;
pid | wait_event_type | wait_event | state |
query
------+-----------------+------------+--------+----------------------------------------------------------------
5074 | | | active | SELECT
pg_create_logical_replication_slot('wow1', 'pgoutput');

With patch applied:
testdb=# SELECT pid, wait_event_type, wait_event, state, query FROM
pg_stat_activity WHERE pid = 62774;
pid | wait_event_type | wait_event | state |
query

-------+-----------------+------------+--------+------------------------------------------------------------------

62774 | IPC | XactDone | active | SELECT *

| | | | FROM
pg_create_logical_replication_slot('my_slot','pgoutput');

(1 row)

[1] https://www.postgresql.org/message-id/flat/CAM45KeELdjhS-rGuvN%3DZLJ_asvZACucZ9LZWVzH7bGcD12DDwg%40mail.gmail.com

Best regards,
Xuneng

Attachment Content-Type Size
0001-Add-new-wait-event-to-XactLockTableWait.patch application/octet-stream 2.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Xuneng Zhou 2025-06-08 14:33:39 Add progressive backoff to XactLockTableWait functions
Previous Message Pavel Stehule 2025-06-08 12:39:35 pg_restore - cannot to restore blobs in dictionary format from older pg dumps