Patch: Show queries of processes holding a lock

Alexey Orlov <aporlov@gmail.com>

From: Alexey Orlov <aporlov@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Date: 2024-09-30T20:15:38Z
Lists: pgsql-hackers

Attachments

Hi, there!

I created patch improving the log messages generated by
log_lock_waits.

Sample output (log_lock_waits=on required):

session 1:
CREATE TABLE foo (val integer);
INSERT INTO foo (val) VALUES (1);
BEGIN;
UPDATE foo SET val = 3;

session 2:
BEGIN;
UPDATE TABLE foo SET val = 2;

Output w/o patch:

LOG: process 3133043 still waiting for ShareLock on transaction 758
after 1000.239 ms
DETAIL: Process holding the lock: 3132855. Wait queue: 3133043.
CONTEXT: while updating tuple (0,7) in relation "foo"
STATEMENT: update foo SET val = 2;

Output with path

LOG: process 3133043 still waiting for ShareLock on transaction 758
after 1000.239 ms
DETAIL: Process holding the lock: 3132855. Wait queue: 3133043.
Process 3132855: update foo SET val = 3;
CONTEXT: while updating tuple (0,7) in relation "foo"
STATEMENT: update foo SET val = 2;

As you can see information about query that holds the lock goes into log.

If this approach proves unacceptable, we can make the log_lock_waits
parameter as an enum
and display the query if the log_lock_waits=verbose (for example).

What do you think?

Regards,

--
Orlov Alexey