Re: Add a permission check to pg_stat_get_backend_subxact()

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: shihao zhong <zhong950419(at)gmail(dot)com>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add a permission check to pg_stat_get_backend_subxact()
Date: 2026-09-22 10:03:10
Message-ID: arJSXjs6szWXIr0H@bdtpg
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Tue, Sep 22, 2026 at 06:24:36PM +0900, Michael Paquier wrote:
> On Mon, Sep 21, 2026 at 09:58:27AM +0000, Bertrand Drouvot wrote:
> > One thing I noticed while looking at this is that with stats_fetch_consistency = snapshot,
> > pgstat_fetch_stat_backend_by_pid() could validate the PID and user from one backend
> > while returning cumulative statistics cached for an older backend that used the
> > same ProcNumber.
>
> I'd slightly prefer storing a user ID, I think, because it means that
> the ACL check is done only based on the stats data, and there would be
> no cross-dependency between the data in the beentry and the stats
> data. Perhaps you have a different view or more ideas?

Yeah, storing the user ID in PgStat_Backend and using it for the ACL check
makes sense to me.

I'm not sure the user ID alone is enough though: if B reuses A's ProcNumber,
pg_stat_get_backend_wal(B_pid) could still return A's cached statistics when
the caller is allowed to see A's data.

I'd keep the PID check from 0002 as well. A generation would be more robust
against PID reuse, as done for example for AIO handles, but introducing a
backend generation seems like too much for this case.

So storing both seems like the simplest approach: the user ID for the ACL
check and the PID for matching the statistics to the requested backend.

Thoughts?

Regards,

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-09-22 10:16:55 Re: Persist slot invalidations before publishing them
Previous Message Amit Kapila 2026-09-22 10:03:01 Re: Logical replication can lose an update after concurrent index invalidation