diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 066f26379e7..5d23121d432 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -2916,7 +2916,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH) * TOC entry types only if their parent object is being restored. * Without selectivity options, we let through everything in the * archive. Note there may be such entries with no parent, eg - * non-default ACLs for built-in objects. + * non-default ACLs for built-in objects. Also, we make + * per-column ACLs additionally depend on the table's ACL if any + * to ensure correct restore order, so those dependencies should + * be ignored in this check. * * This code depends on the parent having been marked already, * which should be the case; if it isn't, perhaps due to @@ -2927,8 +2930,23 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH) * But it's hard to tell which of their dependencies is the one to * consult. */ - if (te->nDeps != 1 || - TocIDRequired(AH, te->dependencies[0]) == 0) + bool dumpthis = false; + + for (int i = 0; i < te->nDeps; i++) + { + TocEntry *pte = getTocEntryByDumpId(AH, te->dependencies[i]); + + if (!pte) + continue; /* probably shouldn't happen */ + if (strcmp(pte->desc, "ACL") == 0) + continue; /* ignore dependency on another ACL */ + if (pte->reqs == 0) + continue; /* this object isn't marked, so ignore it */ + /* Found a parent to be dumped, so we want to dump this too */ + dumpthis = true; + break; + } + if (!dumpthis) return 0; } } diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index 5c2d4505ae2..6006276b89b 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -3586,11 +3586,13 @@ my %tests = ( 'GRANT SELECT ON TABLE measurement' => { create_order => 91, - create_sql => 'GRANT SELECT ON - TABLE dump_test.measurement - TO regress_dump_test_role;', + create_sql => 'GRANT SELECT ON TABLE dump_test.measurement + TO regress_dump_test_role; + GRANT SELECT(city_id) ON TABLE dump_test.measurement + TO "regress_quoted \"" role";', regexp => - qr/^\QGRANT SELECT ON TABLE dump_test.measurement TO regress_dump_test_role;\E/m, + qr/^\QGRANT SELECT ON TABLE dump_test.measurement TO regress_dump_test_role;\E\n.* + ^\QGRANT SELECT(city_id) ON TABLE dump_test.measurement TO "regress_quoted \"" role";\E/xms, like => { %full_runs, %dump_test_schema_runs, section_pre_data => 1, }, unlike => {