diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 71461b339d..c7876fedd2 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -4005,13 +4005,33 @@ getNamespaces(Archive *fout, int *numNamespaces) "LEFT JOIN pg_init_privs pip " "ON (n.oid = pip.objoid " "AND pip.classoid = 'pg_namespace'::regclass " - "AND pip.objsubid = 0) ", + "AND pip.objsubid = 0", username_subquery, acl_subquery->data, racl_subquery->data, init_acl_subquery->data, init_racl_subquery->data); + /* + * When we are doing a 'clean' run, we will be dropping and recreating + * the 'public' schema (the only object which has that kind of + * treatment in the backend and which has an entry in pg_init_privs) + * and therefore we should not consider any initial privileges in + * pg_init_privs in that case. + * + * See pg_backup_archiver.c:_printTocEntry() for the details on why + * the public schema is special in this regard. + * + * Note that if the public schema is dropped and re-created, this is + * essentially a no-op because the new public schema won't have an + * entry in pg_init_privs anyway, as the entry will be removed when + * the public schema is dropped. + */ + if (dopt->outputClean) + appendPQExpBuffer(query," AND pip.objoid <> 'public'::regnamespace"); + + appendPQExpBuffer(query,") "); + destroyPQExpBuffer(acl_subquery); destroyPQExpBuffer(racl_subquery); destroyPQExpBuffer(init_acl_subquery); diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index c51088a49c..b554dcd55e 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -3081,6 +3081,34 @@ qr/^GRANT SELECT ON TABLE test_third_table TO regress_dump_test_role;/m, role => 1, test_schema_plus_blobs => 1, }, }, + 'GRANT USAGE ON SCHEMA public TO public' => { + regexp => qr/^ + \Q--\E\n\n + \QGRANT USAGE ON SCHEMA public TO PUBLIC;\E + /xm, + like => { + clean => 1, + clean_if_exists => 1, }, + unlike => { + binary_upgrade => 1, + createdb => 1, + defaults => 1, + exclude_dump_test_schema => 1, + exclude_test_table => 1, + exclude_test_table_data => 1, + no_blobs => 1, + no_owner => 1, + pg_dumpall_dbprivs => 1, + schema_only => 1, + section_pre_data => 1, + only_dump_test_schema => 1, + only_dump_test_table => 1, + pg_dumpall_globals_clean => 1, + role => 1, + section_data => 1, + section_post_data => 1, + test_schema_plus_blobs => 1, }, }, + 'GRANT commands' => { # catch-all for GRANT commands all_runs => 0, # catch-all regexp => qr/^GRANT /m, @@ -3258,8 +3286,6 @@ qr/^GRANT SELECT ON TABLE test_third_table TO regress_dump_test_role;/m, /xm, like => { binary_upgrade => 1, - clean => 1, - clean_if_exists => 1, createdb => 1, defaults => 1, exclude_dump_test_schema => 1, @@ -3271,6 +3297,8 @@ qr/^GRANT SELECT ON TABLE test_third_table TO regress_dump_test_role;/m, schema_only => 1, section_pre_data => 1, }, unlike => { + clean => 1, + clean_if_exists => 1, only_dump_test_schema => 1, only_dump_test_table => 1, pg_dumpall_globals_clean => 1,