Questa query elencherà tutte le tabelle in tutti i database e gli schemi (commento dalla riga (s) nella clausola WHERE
per filtrare per specifici database, schemi o tabelle), con i privilegi mostrati in ordine in modo che sia facile da vedere se viene concesso un privilegio specifico o no: l'uscita
SELECT grantee
,table_catalog
,table_schema
,table_name
,string_agg(privilege_type, ', ' ORDER BY privilege_type) AS privileges
FROM information_schema.role_table_grants
WHERE grantee != 'postgres'
-- and table_catalog = 'somedatabase' /* uncomment line to filter database */
-- and table_schema = 'someschema' /* uncomment line to filter schema */
-- and table_name = 'sometable' /* uncomment line to filter table */
GROUP BY 1, 2, 3, 4;
Esempio:
grantee |table_catalog |table_schema |table_name |privileges |
--------|----------------|--------------|---------------|---------------|
PUBLIC |adventure_works |pg_catalog |pg_sequence |SELECT |
PUBLIC |adventure_works |pg_catalog |pg_sequences |SELECT |
PUBLIC |adventure_works |pg_catalog |pg_settings |SELECT, UPDATE |
...
vuoi eseguire questo direttamente dal riquadro SQL o riga di comando pg? –
@ DanielL.VanDenBosch: tutti i meta-comandi, come '\ z', sono per psql. E psql è l'interfaccia a riga di comando di PostgreSQL. –