Re: Add a permission check to pg_stat_get_backend_subxact()

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: shihao zhong <zhong950419(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: Add a permission check to pg_stat_get_backend_subxact()
Date: 2026-09-10 15:47:36
Message-ID: ef48668c-cf8e-4f4b-bf39-4b3b9fb9b85a@uni-muenster.de
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 08/09/2026 02:33, shihao zhong wrote:
> pg_stat_get_backend_subxact() does not check the caller's permissions.
> Every other function in the "Per-Backend Statistics Functions" table
> that reports what a session is doing calls HAS_PGSTAT_PERMISSIONS()
> first and returns NULL to a caller who may not see it.  This one is the
> only exception.

pg_stat_get_backend_wal, pg_stat_get_backend_io, and
pg_stat_get_backend_lock also lack this check. Out of scope here, but
perhaps worth a followup patch?

> - adds the HAS_PGSTAT_PERMISSIONS() check, with a regression test that
>   fails without it;

I believe the tests should also cover a non-superuser with explicit
pg_read_all_stats permission (see 0002 attached)

> - documents the rule above that table.  The table says nothing about
>   permissions today; the rule is only written down for the dynamic
>   statistics views;
>
> - corrects one column name in the docs: subxact_overflow should be
>   subxact_overflowed.

The C tuple descriptor still says "subxact_overflow" -- most likely the
source of the confusion.

TupleDescInitEntry(tupdesc, (AttrNumber) 2, "subxact_overflow",
BOOLOID, -1, 0);

Best, Jim

Attachment Content-Type Size
v2-0001-Make-pg_stat_get_backend_subxact-respect-statisti.patch text/x-patch 6.0 KB
v2-0002-Add-test-case-for-explicit-pg_read_all_stats-gran.patch text/x-patch 1.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2026-09-10 15:47:56 Re: PGQ catalog representation and pg_dump support
Previous Message Corey Huinker 2026-09-10 15:46:21 Re: Several issues with postgres_fdw stats import