Re: RFC: Logging plan of the running query
torikoshia <torikoshia@oss.nttdata.com>
From: torikoshia <torikoshia@oss.nttdata.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Atsushi Torikoshi <torikoshia.tech@gmail.com>,
pgsql-hackers@lists.postgresql.org, samimseih@gmail.com,
destrex271@gmail.com
Date: 2025-11-20T01:52:25Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
ecpg: Catch zero-length Unicode identifiers correctly
- a18b6d2dc288 15.0 cited
-
Improve warning message in pg_signal_backend()
- 7fa945b857cc 15.0 cited
-
Add assert to ensure that page locks don't participate in deadlock cycle.
- 72e78d831ab5 13.0 cited
Attachments
- v51-0001-Add-function-to-log-the-plan-of-the-currently-ru.patch (text/x-diff) patch v51-0001
On 2025-11-20 02:23, Robert Haas wrote: > On Mon, Oct 20, 2025 at 8:15 AM torikoshia <torikoshia@oss.nttdata.com> > wrote: >> > S1: Set an injection point to wait in HandleLogQueryPlanInterrupt >> > [runs to completion]. >> > S2: Take an advisory lock [runs to completion]. >> > S1: Start a query that attempts to acquire the same advisory lock. >> > Use $node->wait_for_event() to be sure that S1 is now waiting on the >> > lock. >> > S2: Commit, thus releasing the advisory lock [runs to completion]. >> > Use $node->wait_for_event() to be sure that S1 is now waiting inside >> > HandleLogQueryPlanInterrupt. >> > Remember the log offset, as in >> > src/test/modules/test_misc/t/005_timeouts.pl >> > Detach the injection point. >> > Use $node->wait_for_log() to wait for the expected log message to >> > appear. >> > >> > It's really hard to make these kinds of sequences race-free, so there >> > could well be bugs in the above outline, but I hope it is close to the >> > right thing. >> >> Thanks for the detailed outline! >> Attached patch adds a test following the suggestion. > > Thanks. I'm not sure about this part: > > +# Run pg_log_query_plan(). > +# Then commit the session 2 to release the advisory lock. > +$psql_session2->query_safe( > + qq[ > + SELECT pg_log_query_plan($session1_pid); > + COMMIT; > +]); > > This does two relevant things: one is to send a signal (the SELECT) > and the other is to release a lock (the COMMIT). Both of these events > will soon be perceived by the other session, but I am not sure whether > we have a guarantee about the order. If it's possible for the lock > release to be observed by the target session before the log-query-plan > interrupt arrives, the test will fail. If that is possible, I think we > should try to find a way to plug the gap. I think it's possible. Updated the test so that COMMIT happens only after we confirm that the backend is already waiting at the injection point. > Also, my apologies for taking some time to return to this thread. Not at all -- I really appreciate your continued review. -- Regards, -- Atsushi Torikoshi Seconded from NTT DATA Japan Corporation to SRA OSS K.K.