Re: RFC: Logging plan of the running query

From: torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>
To: Andrei Lepikhov <lepihov(at)gmail(dot)com>
Cc: Lukas Fittl <lukas(at)fittl(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Atsushi Torikoshi <torikoshia(dot)tech(at)gmail(dot)com>, samimseih(at)gmail(dot)com, destrex271(at)gmail(dot)com
Subject: Re: RFC: Logging plan of the running query
Date: 2026-07-01 13:09:52
Message-ID: 8d52f8e281091389aab80710a84d0a14@oss.nttdata.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jun 29, 2026 at 1:23 PM torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>
wrote:
>
> On Wed, Jun 24, 2026 at 11:35 PM Andrei Lepikhov <lepihov(at)gmail(dot)com>
> wrote:
> Thanks for your review!
>
> > 2. GetCurrentQueryDesc, SetCurrentQueryDesc - need 'extern' in the .h
> > file
> > 3. ExplainPrintPlan, ExplainPrintTriggers - have exact duplicates in
> > the explain.h
> > 4. ExplainStringAssemble() has '0' input for a boolean parameter.
> > 5. ExecSetExecProcNodeRecurse: I don't see PlanState::initPlan. Is this
> > intentional?
> > 6. INJECTION_POINT("log-query-interrupt", ...) - it is called inside a
> > signal-safe zone. In tests, the caller might do a lot of things in the
> > attached
> > routine, causing hidden problems later.
>
> I agree that these points should be addressed.
> I'll post an updated patch.

Fixed these points.

> I've also received some off-list feedback, and I'm planning to
> incorporate those comments into the updated patch as well.

I also made the following changes:

- Updated the documentation to mention that pg_log_query_plan() is
asynchronous and that plan logging can be delayed if the target backend
does not reach an executor point where the plan can be inspected.
- Fixed LogQueryPlan() so that its temporary memory context is always
restored and deleted, even when there is no current QueryDesc.
- Added defensive checks for pgstat_get_beentry_by_proc_number()
returning NULL, and verified that the backend status entry still matches
the requested PID.
- Wrapped the main LogQueryPlan() body in PG_TRY/PG_FINALLY so
LogQueryPlanPending and memory context cleanup are handled even if
EXPLAIN generation throws an error.

On Wed, Jul 1, 2026 at 7:42 PM Andrei Lepikhov <lepihov(at)gmail(dot)com>
wrote:
> I took a closer look at the solution

Thanks for the comments!
I will mainly consider the 3rd and 4th points.

Regards,

--
Atsushi Torikoshi
Seconded from NTT DATA CORPORATION to SRA OSS K.K.

Attachment Content-Type Size
v57-0001-Add-function-to-log-the-plan-of-the-currently-ru.patch text/x-diff 38.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-07-01 13:20:32 Re: Centralised architecture detection
Previous Message Roman Khapov 2026-07-01 12:44:17 Re: DROP INVALID INDEXES command