@@ -2,11 +2,51 @@ SELECT table_name
22FROM information_schema.tables
33WHERE table_schema = 'information_schema';
44
5- SELECT grantee, table_name, privilege_type, is_grantable, with_hierarchy
5+ SELECT grantee, table_name, privilege_type, is_grantable, with_hierarchy,
66FROM information_schema.table_privileges
77WHERE table_schema = 'public'
88ORDER BY table_name, privilege_type;
99
1010SELECT grantee, table_name, column_name, privilege_type, is_grantable
1111FROM information_schema.column_privileges
1212WHERE table_schema = 'public';
13+
14+
15+ --
16+ -- GRANT SQL
17+ --
18+ GRANT SELECT (service_type) ON t_computer TO c42ro;
19+
20+ -- selects grants for tables, views, and sequences
21+ SELECT relname
22+ , relacl
23+ , CASE WHEN relkind = 'S' THEN 'SEQUENCE'
24+ WHEN relkind = 'r' THEN 'TABLE'
25+ WHEN relkind = 'v' THEN 'VIEW'
26+ ELSE relkind::varchar END AS type
27+ FROM pg_class
28+ WHERE true --relkind = 'S'
29+ AND relacl IS NOT NULL
30+ AND relnamespace IN (
31+ SELECT oid FROM pg_namespace
32+ WHERE nspname NOT LIKE 'pg_ %' AND nspname != 'information_schema'
33+ );
34+
35+
36+ crashplan=# \dp
37+ ******** * QUERY ********* *
38+ SELECT n.nspname as "Schema",
39+ c.relname as "Name",
40+ CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'S' THEN 'sequence' WHEN 'f' THEN 'foreign table' END as "Type",
41+ pg_catalog.array_to_string(c.relacl, E'\n') AS "Access privileges",
42+ pg_catalog.array_to_string(ARRAY(
43+ SELECT attname || E':\n ' || pg_catalog.array_to_string(attacl, E'\n ')
44+ FROM pg_catalog.pg_attribute a
45+ WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL
46+ ), E'\n') AS "Column access privileges"
47+ FROM pg_catalog.pg_class c
48+ LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
49+ WHERE c.relkind IN ('r', 'v', 'S', 'f')
50+ AND n.nspname !~ '^pg_ ' AND pg_catalog.pg_table_is_visible(c.oid)
51+ ORDER BY 1, 2;
52+ **************************
0 commit comments