Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 156c0c2

Browse files
committed
Fix ordering of GRANT commands in pg_dumpall for tablespaces
This uses a method similar to 68a7c24 and now b8c6014 (applied for database creation), which guarantees that GRANT commands using the WITH GRANT OPTION are dumped in a way so as cascading dependencies are respected. Note that tablespaces do not have support for initial privileges via pg_init_privs, so the same method needs to be applied again. It would be nice to merge all the logic generating ACL queries in dumps under the same banner, but this requires extending the support of pg_init_privs to objects that cannot use it yet, so this is left as future work. Discussion: https://postgr.es/m/20190522071555.GB1278@paquier.xyz Author: Michael Paquier Reviewed-by: Nathan Bossart Backpatch-through: 9.6
1 parent 657c238 commit 156c0c2

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/bin/pg_dump/pg_dumpall.c

+26-7
Original file line numberDiff line numberDiff line change
@@ -1160,19 +1160,38 @@ dumpTablespaces(PGconn *conn)
11601160
*
11611161
* See buildACLQueries() and buildACLCommands().
11621162
*
1163+
* The order in which privileges are in the ACL string (the order they
1164+
* have been GRANT'd in, which the backend maintains) must be preserved to
1165+
* ensure that GRANTs WITH GRANT OPTION and subsequent GRANTs based on
1166+
* those are dumped in the correct order.
1167+
*
11631168
* Note that we do not support initial privileges (pg_init_privs) on
1164-
* tablespaces.
1169+
* tablespaces, so this logic cannot make use of buildACLQueries().
11651170
*/
11661171
if (server_version >= 90600)
11671172
res = executeQuery(conn, "SELECT oid, spcname, "
11681173
"pg_catalog.pg_get_userbyid(spcowner) AS spcowner, "
11691174
"pg_catalog.pg_tablespace_location(oid), "
1170-
"(SELECT pg_catalog.array_agg(acl) FROM (SELECT pg_catalog.unnest(coalesce(spcacl,pg_catalog.acldefault('t',spcowner))) AS acl "
1171-
"EXCEPT SELECT pg_catalog.unnest(pg_catalog.acldefault('t',spcowner))) as foo)"
1172-
"AS spcacl,"
1173-
"(SELECT pg_catalog.array_agg(acl) FROM (SELECT pg_catalog.unnest(pg_catalog.acldefault('t',spcowner)) AS acl "
1174-
"EXCEPT SELECT pg_catalog.unnest(coalesce(spcacl,pg_catalog.acldefault('t',spcowner)))) as foo)"
1175-
"AS rspcacl,"
1175+
"(SELECT array_agg(acl ORDER BY row_n) FROM "
1176+
" (SELECT acl, row_n FROM "
1177+
" unnest(coalesce(spcacl,acldefault('t',spcowner))) "
1178+
" WITH ORDINALITY AS perm(acl,row_n) "
1179+
" WHERE NOT EXISTS ( "
1180+
" SELECT 1 "
1181+
" FROM unnest(acldefault('t',spcowner)) "
1182+
" AS init(init_acl) "
1183+
" WHERE acl = init_acl)) AS spcacls) "
1184+
" AS spcacl, "
1185+
"(SELECT array_agg(acl ORDER BY row_n) FROM "
1186+
" (SELECT acl, row_n FROM "
1187+
" unnest(acldefault('t',spcowner)) "
1188+
" WITH ORDINALITY AS initp(acl,row_n) "
1189+
" WHERE NOT EXISTS ( "
1190+
" SELECT 1 "
1191+
" FROM unnest(coalesce(spcacl,acldefault('t',spcowner))) "
1192+
" AS permp(orig_acl) "
1193+
" WHERE acl = orig_acl)) AS rspcacls) "
1194+
" AS rspcacl, "
11761195
"array_to_string(spcoptions, ', '),"
11771196
"pg_catalog.shobj_description(oid, 'pg_tablespace') "
11781197
"FROM pg_catalog.pg_tablespace "

0 commit comments

Comments
 (0)