diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 049b79fba9..93930c6197 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -2898,7 +2898,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 @@ -2909,8 +2912,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 de435983b4..4402ba7fe5 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -3301,11 +3301,13 @@ my %tests = ( 'GRANT SELECT ON TABLE measurement' => { create_order => 91, - create_sql => 'GRANT SELECT ON - TABLE dump_test.measurement + 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_dump_test_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_dump_test_role;\E/xms, like => { %full_runs, %dump_test_schema_runs, section_pre_data => 1, }, unlike => {