@@ -68,14 +68,44 @@ Branch: REL9_4_STABLE [b51c8efc6] 2017-08-24 15:21:32 -0700
68
68
in an existing installation, you can, as a superuser, do this
69
69
in <application>psql</>:
70
70
<programlisting>
71
- BEGIN;
72
- DROP SCHEMA information_schema CASCADE;
73
- \i <replaceable>SHAREDIR</>/information_schema.sql
74
- COMMIT;
71
+ SET search_path TO information_schema;
72
+ CREATE OR REPLACE VIEW table_privileges AS
73
+ SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
74
+ CAST(grantee.rolname AS sql_identifier) AS grantee,
75
+ CAST(current_database() AS sql_identifier) AS table_catalog,
76
+ CAST(nc.nspname AS sql_identifier) AS table_schema,
77
+ CAST(c.relname AS sql_identifier) AS table_name,
78
+ CAST(c.prtype AS character_data) AS privilege_type,
79
+ CAST(
80
+ CASE WHEN
81
+ -- object owner always has grant options
82
+ pg_has_role(grantee.oid, c.relowner, 'USAGE')
83
+ OR c.grantable
84
+ THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable,
85
+ CAST(CASE WHEN c.prtype = 'SELECT' THEN 'YES' ELSE 'NO' END AS yes_or_no) AS with_hierarchy
86
+
87
+ FROM (
88
+ SELECT oid, relname, relnamespace, relkind, relowner, (aclexplode(coalesce(relacl, acldefault('r', relowner)))).* FROM pg_class
89
+ ) AS c (oid, relname, relnamespace, relkind, relowner, grantor, grantee, prtype, grantable),
90
+ pg_namespace nc,
91
+ pg_authid u_grantor,
92
+ (
93
+ SELECT oid, rolname FROM pg_authid
94
+ UNION ALL
95
+ SELECT 0::oid, 'PUBLIC'
96
+ ) AS grantee (oid, rolname)
97
+
98
+ WHERE c.relnamespace = nc.oid
99
+ AND c.relkind IN ('r', 'v', 'f')
100
+ AND c.grantee = grantee.oid
101
+ AND c.grantor = u_grantor.oid
102
+ AND c.prtype IN ('INSERT', 'SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER')
103
+ AND (pg_has_role(u_grantor.oid, 'USAGE')
104
+ OR pg_has_role(grantee.oid, 'USAGE')
105
+ OR grantee.rolname = 'PUBLIC');
75
106
</programlisting>
76
- (Run <literal>pg_config --sharedir</> if you're uncertain
77
- where <replaceable>SHAREDIR</> is.) This must be repeated in each
78
- database to be fixed.
107
+ This must be repeated in each database to be fixed,
108
+ including <literal>template0</>.
79
109
</para>
80
110
</listitem>
81
111
0 commit comments