Skip to content

Commit b8c6014

Browse files
committed
Fix ordering of GRANT commands in pg_dump for database creation
This uses a method similar to 68a7c24, which guarantees that GRANT commands using the WITH GRANT OPTION are dumped in a way so as cascading dependencies are respected. As databases do not have support for initial privileges via pg_init_privs, we need to repeat again the same ACL reordering method. ACL for databases have been moved from pg_dumpall to pg_dump in v11, so this impacts pg_dump for v11 and above, and pg_dumpall for v9.6 and v10. Discussion: https://postgr.es/m/15788-4e18847520ebcc75@postgresql.org Author: Nathan Bossart Reviewed-by: Haribabu Kommi Backpatch-through: 9.6
1 parent 5eb4a51 commit b8c6014

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,20 +2664,41 @@ dumpDatabase(Archive *fout)
26642664

26652665
pg_log_info("saving database definition");
26662666

2667-
/* Fetch the database-level properties for this database */
2667+
/*
2668+
* Fetch the database-level properties for this database.
2669+
*
2670+
* The order in which privileges are in the ACL string (the order they
2671+
* have been GRANT'd in, which the backend maintains) must be preserved to
2672+
* ensure that GRANTs WITH GRANT OPTION and subsequent GRANTs based on
2673+
* those are dumped in the correct order. Note that initial privileges
2674+
* (pg_init_privs) are not supported on databases, so this logic cannot
2675+
* make use of buildACLQueries().
2676+
*/
26682677
if (fout->remoteVersion >= 90600)
26692678
{
26702679
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, datname, "
26712680
"(%s datdba) AS dba, "
26722681
"pg_encoding_to_char(encoding) AS encoding, "
26732682
"datcollate, datctype, datfrozenxid, datminmxid, "
2674-
"(SELECT array_agg(acl ORDER BY acl::text COLLATE \"C\") FROM ( "
2675-
" SELECT unnest(coalesce(datacl,acldefault('d',datdba))) AS acl "
2676-
" EXCEPT SELECT unnest(acldefault('d',datdba))) as datacls)"
2683+
"(SELECT array_agg(acl ORDER BY row_n) FROM "
2684+
" (SELECT acl, row_n FROM "
2685+
" unnest(coalesce(datacl,acldefault('d',datdba))) "
2686+
" WITH ORDINALITY AS perm(acl,row_n) "
2687+
" WHERE NOT EXISTS ( "
2688+
" SELECT 1 "
2689+
" FROM unnest(acldefault('d',datdba)) "
2690+
" AS init(init_acl) "
2691+
" WHERE acl = init_acl)) AS datacls) "
26772692
" AS datacl, "
2678-
"(SELECT array_agg(acl ORDER BY acl::text COLLATE \"C\") FROM ( "
2679-
" SELECT unnest(acldefault('d',datdba)) AS acl "
2680-
" EXCEPT SELECT unnest(coalesce(datacl,acldefault('d',datdba)))) as rdatacls)"
2693+
"(SELECT array_agg(acl ORDER BY row_n) FROM "
2694+
" (SELECT acl, row_n FROM "
2695+
" unnest(acldefault('d',datdba)) "
2696+
" WITH ORDINALITY AS initp(acl,row_n) "
2697+
" WHERE NOT EXISTS ( "
2698+
" SELECT 1 "
2699+
" FROM unnest(coalesce(datacl,acldefault('d',datdba))) "
2700+
" AS permp(orig_acl) "
2701+
" WHERE acl = orig_acl)) AS rdatacls) "
26812702
" AS rdatacl, "
26822703
"datistemplate, datconnlimit, "
26832704
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy