Re: Permission select pg_stat_replication

From: Denish Patel <denish(at)omniti(dot)com>
To: jesse(dot)waters(at)gmail(dot)com
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Permission select pg_stat_replication
Date: 2015-04-01 15:46:46
Message-ID: CAFddxvOFPANK222gvLhnu-0GyAmd9DCBag_GMC26tfZ4rH-n1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-hackers

Hey Jesse,

you should be able to use secure_check_postgres method to avoid granting
SUPER permission on monitoring user.

Example:

1. Create a function that extracts all from pg_stat_replication:

create or replace function pg_stat_repl() returns setof
pg_catalog.pg_stat_replication as $$begin return query(select * from
pg_catalog.pg_stat_replication); end$$ language plpgsql security definer;

2. Create a view that uses this function to get data in it:

create view public.pg_stat_repl as select * from pg_stat_repl();

3. Grant select on this view to your unprivileged user, sat 'common_user' :

grant select on public.pg_stat_repl to common_user;

After this, you can do a select on this view to get the required
information. You can do this for other pg_catalog functions as well.
Reference -
https://github.com/xzilla/secure_check_postgres/blob/master/sql/pg_stat_activity.sql

Hope this helps.

On Tue, Mar 31, 2015 at 8:47 AM, <jesse(dot)waters(at)gmail(dot)com> wrote:

> Hello,
>
> Could someone tell me what permission is required to
> select * from pg_stat_replication; ?
>
> I like to setup a monitor to query database with minimal privileges
> necessary.
>
> TIA,
>
> Jesse
>
>
> --
> Sent via pgsql-admin mailing list (pgsql-admin(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin
>

--
Denish Patel,
OmniTI Computer Consulting Inc.
Database Architect,
http://omniti.com/does/data-management
http://www.pateldenish.com

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Stephen Frost 2015-04-01 15:53:02 Re: Permission select pg_stat_replication
Previous Message Stephen Frost 2015-04-01 00:35:26 Re: Permission select pg_stat_replication

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2015-04-01 15:48:37 Re: Zero-padding and zero-masking fixes for to_char(float)
Previous Message David Fetter 2015-04-01 15:40:27 Re: Bug fix for missing years in make_date()