Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: Show all the privileges for a concrete user

How to make a query to the Postgres data dictionary to find out all the privileges that a particular user has.

I've been looking for a solution and I can not find anything. Thanks and good day

like image 516
Python241820 Avatar asked Nov 23 '16 08:11

Python241820


People also ask

How do I see Postgres user privileges?

Another way to do this is to use the information_schema schema and query the table_privileges table as: $ SELECT * FROM information_schema. table_privileges LIMIT 5; The above query will show detailed information about user privileges on databases as well as tables.

How is the super user in PostgreSQL?

A superuser in PostgreSQL is a user who bypasses all permission checks. Superusers can run commands that can destabilize or crash the database server (e.g., create C functions) and access the operating system. Show activity on this post. Superuser is per database.

What is usage privileges in PostgreSQL?

The view usage_privileges identifies USAGE privileges granted on various kinds of objects to a currently enabled role or by a currently enabled role. In PostgreSQL, this currently applies to collations, domains, foreign-data wrappers, foreign servers, and sequences.


1 Answers

table permissions:

select   *  from information_schema.role_table_grants  where grantee='YOUR_USER' ; 

ownership:

select     *  from pg_tables  where tableowner = 'YOUR_USER' ; 

schema permissions:

select     r.usename as grantor, e.usename as grantee, nspname, privilege_type, is_grantable from pg_namespace join lateral (   SELECT     *   from     aclexplode(nspacl) as x ) a on true join pg_user e on a.grantee = e.usesysid join pg_user r on a.grantor = r.usesysid   where e.usename = 'YOUR_USER' ; 
like image 130
Vao Tsun Avatar answered Oct 03 '22 12:10

Vao Tsun