Listing all permissions in PostgreSQL

Filed under: Development, SQL — lars @ 09:40:33 am

I've just spent some time trying to debug a permissions issue in PostgreSQL that kept giving me the error "permission denied for <tablename>" when trying to access a view - even though I appeared to have all the required permissions for the table underlying the view.

I found the following useful sql to list all user permissions on every database object, which helped me find the cause of the problem:

SELECT relname as "Relation", relacl as "Access permissions"
FROM pg_class
WHERE  relkind IN ('r', 'v', 'S')
AND relname !~ '^pg_'
ORDER BY relname;

In my case, the view was referring to a sequence that I didn't have permissions to read from, and I'd never have found this without the above SQL.

Comments

No Comments for this post yet...

    Leave a comment

    Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>


    Options:
    (Line breaks become <br />)
    (Set cookies for name, email & url)




    powered by  b2evolution