I need to determine what privileges are currently granted for some materialized views in my database.
The query to do this for a table or standard view is pretty straight forward:
SELECT grantee, string_agg(privilege_type, ', ') AS privileges
FROM information_schema.table_privileges
WHERE table_schema = 'some_schema' AND table_name = 'some_table'
GROUP by grantee;
That said, there doesn't seem to be an analogous table for materialized views. Where does PostgreSQL store this information?
Following klin's helpful answer, I've come up with a view that lists a summary of all privileges for all relations that appear in
pg_class
(tables, views, m. views, indexes, sequences, foreign tables, composite types) for all roles:In Postgres system catalogs are the basic set of complete information about the installation and databases. System catalogs are the most reliable source of information. Information schema as an auxiliary feature is based on system catalogs and is provided for compatibility with other RDBMs:
Materialized views are not SQL-standard objects hence the information schema does not contain information about them.
The system catalog
pg_class
contains all informations on privileges in the columnrelacl
.If the column is
null
then the owner has all privileges.An empty string as a user name in
acl
string meanspublic
.You need a function to show privileges in readable format:
Use: