Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Postgres access for a user

I have looked into the documentation for GRANT Found here and I was trying to see if there is a built-in function that can let me look at what level of accessibility I have in databases. Of course there is:

\dp and \dp mytablename

But this does not show what my account has access to. I would like to see ALL the tables I have access to. Can anyone tell me if there is a command that can check my level of access in Postgres (whether I have SELECT, INSERT, DELETE, UPDATE privileges)? And if so, what would that command be?

like image 579
ryekayo Avatar asked Nov 13 '14 20:11

ryekayo


People also ask

How do I check PostgreSQL user permissions?

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 my user in PostgreSQL?

PostgreSQL: Find Users in PostgreSQL Answer: In PostgreSQL, there is a system table called pg_user. You can run a query against this system table that returns all of the Users that have been created in PostgreSQL as well as information about these Users.


1 Answers

You could query the table_privileges table in the information schema:

SELECT table_catalog, table_schema, table_name, privilege_type FROM   information_schema.table_privileges  WHERE  grantee = 'MY_USER' 
like image 63
Mureinik Avatar answered Oct 13 '22 00:10

Mureinik