Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query grants for a table in postgres

How can I query all GRANTS granted to an object in postgres?

For example I have table "mytable":

GRANT SELECT, INSERT ON mytable TO user1
GRANT UPDATE ON mytable TO user2 

I need somthing which gives me:

user1: SELECT, INSERT
user2: UPDATE
like image 376
markus Avatar asked Sep 07 '11 15:09

markus


People also ask

How do I find grants on my table?

To determine which users have direct grant access to a table we'll use the DBA_TAB_PRIVS view: SELECT * FROM DBA_TAB_PRIVS; You can check the official documentation for more information about the columns returned from this query, but the critical columns are: GRANTEE is the name of the user with granted access.

How do I find grant privileges in PostgreSQL?

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.

What is grantee in Postgres?

grantee sql_identifier. Name of the role that the privilege was granted to. table_catalog sql_identifier. Name of the database that contains the table (always the current database)


2 Answers

I already found it:

SELECT grantee, privilege_type 
FROM information_schema.role_table_grants 
WHERE table_name='mytable'
like image 92
markus Avatar answered Oct 19 '22 20:10

markus


\z mytable from psql gives you all the grants from a table, but you'd then have to split it up by individual user.

like image 109
CPJ Avatar answered Oct 19 '22 21:10

CPJ