Re: Allow pg_read_all_stats to read replication origin status

From: solai v <solai(dot)cdac(at)gmail(dot)com>
To: Virender Singla <virender(dot)cse(at)gmail(dot)com>
Cc: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Shubhra Jain <shubhra(dot)jain(at)ksolves(dot)com>, Dilip Kumar <DilipBalaut(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allow pg_read_all_stats to read replication origin status
Date: 2026-12-04 09:21:37
Message-ID: CAF0whudk48XVhyq--fnmAfUYiZem4-WGniErDxusifsKrw6nSQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

On Fri, Dec 4, 2026 at 10:15 AM Virender Singla <virender(dot)cse(at)gmail(dot)com> wrote:
>
> Thanks for taking a look, I attached the v3 version with the refinements.
>
> > 01.
> > ```
> > +GRANT EXECUTE ON FUNCTION pg_show_replication_origin_status() TO pg_read_all_stats;
> > ```
> > I cannot find existing examples to GRANT EXECUTION in the file. Per my quick
> > lookup it's controled under the pg_proc.dat.
>
> Looks like I was working on an older copy. Since commit f95d73ed433
> ("Simplify creation of built-in functions with non-default ACLs",
> [1]), non-default ACLs for built-in functions are moved from
> system_functions.sql/system_views.sql. v3 follows that now.
>
> > 02.
> > ```
> > +SELECT has_function_privilege('regress_readallstats','pg_show_replication_origin_status()','EXECUTE'); -- no
> > ```
> > Do we have to check the internal function? E.g., a view pg_dsm_registry_allocations
> > is a wrapper of pg_get_dsm_registry_allocations but the latter one is not tested.
>
> I dropped the has_function_privilege() checks. As with the other
> pg_read_all_stats views, the SELECT COUNT(*) on the view run as a
> member of pg_read_all_stats already exercises EXECUTE on the backing
> function
>
> [1] https://postgr.es/m/183292bb-4891-4c96-a3ca-e78b5e0e1358@dunslane.net
>

I have reviewed and tested the updated patch. The proposed changes
give the intended results. Granting SELECT access on
pg_replication_origin_status to pg_read_all_stats, along with EXECUTE
permission on the underlying pg_show_replication_origin_status()
function, provides the required access while retaining the existing
restriction for ordinary users. I also verified that members of
pg_read_all_stats can successfully query the view, members of
pg_monitor can access the view through their membership in
pg_read_all_stats, ordinary users without the required role membership
continue to receive a permission-denied error, The underlying function
can be executed by members of pg_read_all_stats and the focused
privileges regression test and the complete PostgreSQL regression test
suite pass successfully. The implementation also addresses the review
comments discussed in the thread. The function's EXECUTE privilege is
now defined in pg_proc.dat instead of system_views.sql and the
separate has_function_privilege() checks have been removed, as
querying the view itself verifies the function's execution privilege..
Overall, I did not identify any issues in the reviewed changes. The
patch looks good to me based on the testing performed.

Regards,
Solai

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ivan Alekseev 2026-12-04 09:22:15 Re: [PATCH] Allow NOTIFY without cross-transaction commit ordering
Previous Message John Naylor 2026-12-04 09:20:35 Re: Improving scalability of Parallel Bitmap Heap/Index Scan