Re: Adding per backend commit and rollback counters

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Kuba Knysiak <thesniboy(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Adding per backend commit and rollback counters
Date: 2026-03-31 09:24:35
Message-ID: acuS01xZX9Ik2CKW@ip-10-97-1-34.eu-west-3.compute.internal
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, Mar 30, 2026 at 08:19:13PM +0000, Kuba Knysiak wrote:
> Hello,
> after reviewing the patch together with Miłosz, we found the following:

Thanks for the review!

> - In pgstatfuncs.c, we call pgstat_fetch_stat_backend_by_pid(beentry->st_procpid, NULL)
> for each backend row. That path acquires ProcArrayLock via BackendPidGetProc(),
> so this repeats lock acquisition for every row. We could simplify this and avoid
> taking the lock altogether by fetching directly with
> pgstat_fetch_stat_backend(local_beentry->proc_number).

Yeah, I think that's a good point. Done that way in the attached. Also adding a
check on the backend type as it was done in pgstat_fetch_stat_backend_by_pid().

> Also, shouldn't this patch bump catversion?

Yes and that was mentioned in the 0003 commit message. We usually don't change
it in the patch itself (could easily produce rebase noise) but just put an
XXX in the commit message so that it's not forgoten when pushed.

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v5-0001-Adding-per-backend-commit-and-rollback-counters.patch text/x-diff 5.8 KB
v5-0002-Adding-XID-generation-count-per-backend.patch text/x-diff 2.7 KB
v5-0003-Adding-the-pg_stat_backend_transaction-view.patch text/x-diff 13.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-03-31 09:29:38 Re: WIP - xmlvalidate implementation from TODO list
Previous Message Amit Langote 2026-03-31 09:17:16 Re: Eliminating SPI / SQL from some RI triggers - take 3