Re: Stack-based tracking of per-node WAL/buffer usage

From: Lukas Fittl <lukas(at)fittl(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, Tomas Vondra <tomas(at)vondra(dot)me>, Peter Smith <smithpb2250(at)gmail(dot)com>
Subject: Re: Stack-based tracking of per-node WAL/buffer usage
Date: 2026-04-05 19:38:58
Message-ID: CAP53Pky4zHCueAyPkWE-cH6SqE_m+Kppmy=zE5K36X3HvCFZLw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Apr 5, 2026 at 11:13 AM Andres Freund <andres(at)anarazel(dot)de> wrote:
> Unfortunately I think 0001 on its own doesn't actually work correctly. I
> luckily tried an EXPLAIN ANALYZE with triggers and noticed that the time is
> reported as zeroes.
>
> The only reason I tried is because I misread the diff and though you'd changed
> the calls=%.3f to calls=%d, even though the old state is calls=%.0f...
>
>
> The reason it doesn't work is that explain shows tginstr->instr.total, but
> with the patch the trigger instrumentation just computes
> tginstr->instr.{counter,firsttuple}.

Argh, good catch. That's on me for not manually testing it when I
factored it out.

I've confirmed this works now, both with 0001 only, and with 0001+0002.

> But probably the least bad solution is to add an InstrEndLoop() to in 0001 and
> remove it again in 0002.

Yeah, I've done that for now.

>
> Re 0002
>
> In passing, drop the "n" argument to InstrAlloc, as all remaining callers
> need exactly one Instrumentation struct.
>
> I think that probably should be in 0001?

Ack, done.

>
>
> I'm kinda wondering whether, to keep the line lenghts manageable,
> --- a/src/backend/commands/explain.c
> +++ b/src/backend/commands/explain.c
> @@ -1837,7 +1837,7 @@ ExplainNode(PlanState *planstate, List *ancestors,
> {
> double nloops = planstate->instrument->nloops;
> double startup_ms = INSTR_TIME_GET_MILLISEC(planstate->instrument->startup) / nloops;
> - double total_ms = INSTR_TIME_GET_MILLISEC(planstate->instrument->total) / nloops;
> + double total_ms = INSTR_TIME_GET_MILLISEC(planstate->instrument->instr.total) / nloops;
> double rows = planstate->instrument->ntuples / nloops;
>
> Should store planstate->instrument in a local var and wrap after =.
>
> But not sure it's worth bothering with.

Sure, seems easy enough.

See attached v14 with changes to 0001 and 0002 only. I've also moved
the PBHS/PIOS patches to their own thread [0].

Thanks,
Lukas

[0]: https://www.postgresql.org/message-id/CAP53PkxRrRKLXECGNFTVOtUusBoWLutZiPfnbejX40ocLuFMQA@mail.gmail.com

--
Lukas Fittl

Attachment Content-Type Size
v14-0005-instrumentation-Add-additional-regression-tests-.patch application/octet-stream 22.5 KB
v14-0003-instrumentation-Use-Instrumentation-instead-of-m.patch application/octet-stream 19.3 KB
v14-0002-instrumentation-Separate-per-node-logic-from-oth.patch application/octet-stream 27.9 KB
v14-0004-instrumentation-Replace-direct-changes-of-pgBuff.patch application/octet-stream 9.0 KB
v14-0001-instrumentation-Separate-trigger-logic-from-othe.patch application/octet-stream 13.9 KB
v14-0006-Optimize-measuring-WAL-buffer-usage-through-stac.patch application/octet-stream 89.6 KB
v14-0009-Index-scans-Show-table-buffer-accesses-separatel.patch application/octet-stream 22.9 KB
v14-0007-instrumentation-Use-Instrumentation-struct-for-p.patch application/octet-stream 29.2 KB
v14-0008-instrumentation-Optimize-ExecProcNodeInstr-instr.patch application/octet-stream 11.3 KB
v14-0010-Add-test_session_buffer_usage-test-module.patch application/octet-stream 30.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-04-05 19:40:48 Re: Parallel Bitmap Heap Scan reports per-worker stats in EXPLAIN ANALYZE
Previous Message Heikki Linnakangas 2026-04-05 19:35:58 Re: Better shared data structure management and resizable shared data structures