pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedList user who have access to schema
6+ messages / 5 participants
[nested] [flat]
* List user who have access to schema
@ 2018-08-02 17:49 Suresh Raja <suresh.rajaabc@gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Suresh Raja @ 2018-08-02 17:49 UTC (permalink / raw)
To: pgsql-general; pgsql-sql@postgresql.org
Hi All:
I'm looking for query which can list all users who have access to a
particular schema.
The user may be granted role, which is turn may have access to the schema.
If the schema name is sch1,
grant select on table sch1.tab1 to role_ro;
grant ALL on table sch1.tab1 to role_rw;
grant role_ro to user1;
grant role_rw to user2;
I'm looking for report like
Schema | Role | Username
------------------------------------------------------------------------
sch1 role_ro user1, user3
role_rw user2, user4
Thanks in advance,
-SR
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: List user who have access to schema
@ 2018-08-02 17:58 Tom Lane <tgl@sss.pgh.pa.us>
parent: Suresh Raja <suresh.rajaabc@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Tom Lane @ 2018-08-02 17:58 UTC (permalink / raw)
To: Suresh Raja <suresh.rajaabc@gmail.com>; +Cc: pgsql-general; pgsql-sql@postgresql.org
Suresh Raja <suresh.rajaabc@gmail.com> writes:
> I'm looking for query which can list all users who have access to a
> particular schema.
Something involving
SELECT ... FROM pg_user
WHERE has_schema_privilege(usename, 'schema-of-interest', 'usage');
would probably be what you want.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: List user who have access to schema
@ 2018-08-02 18:23 Suresh Raja <suresh.rajaabc@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 6+ messages in thread
From: Suresh Raja @ 2018-08-02 18:23 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general; pgsql-sql@postgresql.org
yes ... how can i pass variable * to the function has_schema_privilege(*,
'schema-of-interest', 'usage');
Thanks!
On Thu, Aug 2, 2018 at 12:58 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Suresh Raja <suresh.rajaabc@gmail.com> writes:
> > I'm looking for query which can list all users who have access to a
> > particular schema.
>
> Something involving
>
> SELECT ... FROM pg_user
> WHERE has_schema_privilege(usename, 'schema-of-interest', 'usage');
>
> would probably be what you want.
>
> regards, tom lane
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: List user who have access to schema
@ 2018-08-02 18:42 David G. Johnston <david.g.johnston@gmail.com>
parent: Suresh Raja <suresh.rajaabc@gmail.com>
1 sibling, 0 replies; 6+ messages in thread
From: David G. Johnston @ 2018-08-02 18:42 UTC (permalink / raw)
To: Suresh Raja <suresh.rajaabc@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general; pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
On Thursday, August 2, 2018, Suresh Raja <suresh.rajaabc@gmail.com> wrote:
> yes ... how can i pass variable * to the function has_schema_privilege(*,
> 'schema-of-interest', 'usage');
>
You cannot...you must execute the function once for every user, hence the
original query's from clause.
David J.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: List user who have access to schema
@ 2018-08-02 18:47 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Suresh Raja <suresh.rajaabc@gmail.com>
1 sibling, 0 replies; 6+ messages in thread
From: Adrian Klaver @ 2018-08-02 18:47 UTC (permalink / raw)
To: Suresh Raja <suresh.rajaabc@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general; pgsql-sql@postgresql.org
On 08/02/2018 11:23 AM, Suresh Raja wrote:
> yes ... how can i pass variable * to the function
> has_schema_privilege(*, 'schema-of-interest', 'usage');
PREPARE schema_user(varchar, varchar) AS SELECT * FROM pg_user
WHERE has_schema_privilege($1, $2, 'create');
EXECUTE schema_user ('aklaver', 'public');
DEALLOCATE schema_user ;
>
> Thanks!
>
> On Thu, Aug 2, 2018 at 12:58 PM, Tom Lane <tgl@sss.pgh.pa.us
> <mailto:tgl@sss.pgh.pa.us>> wrote:
>
> Suresh Raja <suresh.rajaabc@gmail.com
> <mailto:suresh.rajaabc@gmail.com>> writes:
> > I'm looking for query which can list all users who have access to a
> > particular schema.
>
> Something involving
>
> SELECT ... FROM pg_user
> WHERE has_schema_privilege(usename, 'schema-of-interest', 'usage');
>
> would probably be what you want.
>
> regards, tom lane
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: List user who have access to schema
@ 2018-08-03 14:26 pinker <pinker@onet.eu>
parent: Suresh Raja <suresh.rajaabc@gmail.com>
1 sibling, 0 replies; 6+ messages in thread
From: pinker @ 2018-08-03 14:26 UTC (permalink / raw)
To: pgsql-general
I think this one will give you report you need:
select schema_name,
roleid::regrole,
string_agg(member::regrole::text,',' order by member::regrole::text) users
from information_schema.schemata s, pg_user u
JOIN pg_auth_members a ON u.usename::text=a.roleid::regrole::text
WHERE s.schema_name not like 'pg_%' AND has_schema_privilege(usename,
s.schema_name, 'usage')
GROUP BY s.schema_name, roleid::regrole, u.usename
order by 1;
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2018-08-03 14:26 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-02 17:49 List user who have access to schema Suresh Raja <suresh.rajaabc@gmail.com>
2018-08-02 17:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-08-02 18:23 ` Suresh Raja <suresh.rajaabc@gmail.com>
2018-08-02 18:42 ` David G. Johnston <david.g.johnston@gmail.com>
2018-08-02 18:47 ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-08-03 14:26 ` pinker <pinker@onet.eu>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox