|
52 | 52 | in an existing installation, you can, as a superuser, do this
|
53 | 53 | in <application>psql</>:
|
54 | 54 | <programlisting>
|
55 |
| -BEGIN; |
56 |
| -DROP SCHEMA information_schema CASCADE; |
57 |
| -\i <replaceable>SHAREDIR</>/information_schema.sql |
58 |
| -COMMIT; |
| 55 | +SET search_path TO information_schema; |
| 56 | +CREATE OR REPLACE VIEW table_privileges AS |
| 57 | + SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor, |
| 58 | + CAST(grantee.rolname AS sql_identifier) AS grantee, |
| 59 | + CAST(current_database() AS sql_identifier) AS table_catalog, |
| 60 | + CAST(nc.nspname AS sql_identifier) AS table_schema, |
| 61 | + CAST(c.relname AS sql_identifier) AS table_name, |
| 62 | + CAST(c.prtype AS character_data) AS privilege_type, |
| 63 | + CAST( |
| 64 | + CASE WHEN |
| 65 | + -- object owner always has grant options |
| 66 | + pg_has_role(grantee.oid, c.relowner, 'USAGE') |
| 67 | + OR c.grantable |
| 68 | + THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable, |
| 69 | + CAST(CASE WHEN c.prtype = 'SELECT' THEN 'YES' ELSE 'NO' END AS yes_or_no) AS with_hierarchy |
| 70 | + |
| 71 | + FROM ( |
| 72 | <
C84A
code class="diff-text syntax-highlighted-line addition">+ SELECT oid, relname, relnamespace, relkind, relowner, (aclexplode(coalesce(relacl, acldefault('r', relowner)))).* FROM pg_class |
| 73 | + ) AS c (oid, relname, relnamespace, relkind, relowner, grantor, grantee, prtype, grantable), |
| 74 | + pg_namespace nc, |
| 75 | + pg_authid u_grantor, |
| 76 | + ( |
| 77 | + SELECT oid, rolname FROM pg_authid |
| 78 | + UNION ALL |
| 79 | + SELECT 0::oid, 'PUBLIC' |
| 80 | + ) AS grantee (oid, rolname) |
| 81 | + |
| 82 | + WHERE c.relnamespace = nc.oid |
| 83 | + AND c.relkind IN ('r', 'v', 'f') |
| 84 | + AND c.grantee = grantee.oid |
| 85 | + AND c.grantor = u_grantor.oid |
| 86 | + AND c.prtype IN ('INSERT', 'SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER') |
| 87 | + AND (pg_has_role(u_grantor.oid, 'USAGE') |
| 88 | + OR pg_has_role(grantee.oid, 'USAGE') |
| 89 | + OR grantee.rolname = 'PUBLIC'); |
59 | 90 | </programlisting>
|
60 |
| - (Run <literal>pg_config --sharedir</> if you're uncertain |
61 |
| - where <replaceable>SHAREDIR</> is.) This must be repeated in each |
62 |
| - database to be fixed. |
| 91 | + This must be repeated in each database to be fixed, |
| 92 | + including <literal>template0</>. |
63 | 93 | </para>
|
64 | 94 | </listitem>
|
65 | 95 |
|
|
0 commit comments