Skip to content

Commit 4e23c47

Browse files
committed
Fix identify_locking_dependencies for schema-only dumps.
Without this fix, parallel restore of a schema-only dump can deadlock, because when the dump is schema-only, the dependency will still be pointing at the TABLE item rather than the TABLE DATA item. Robert Haas and Tom Lane
1 parent d99d0e6 commit 4e23c47

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,11 +4137,14 @@ identify_locking_dependencies(ArchiveHandle *AH, TocEntry *te)
41374137
return;
41384138

41394139
/*
4140-
* We assume the item requires exclusive lock on each TABLE DATA item
4141-
* listed among its dependencies. (This was originally a dependency on
4142-
* the TABLE, but fix_dependencies repointed it to the data item. Note
4143-
* that all the entry types we are interested in here are POST_DATA, so
4144-
* they will all have been changed this way.)
4140+
* We assume the entry requires exclusive lock on each TABLE or TABLE DATA
4141+
* item listed among its dependencies. Originally all of these would have
4142+
* been TABLE items, but repoint_table_dependencies would have repointed
4143+
* them to the TABLE DATA items if those are present (which they might not
4144+
* be, eg in a schema-only dump). Note that all of the entries we are
4145+
* processing here are POST_DATA; otherwise there might be a significant
4146+
* difference between a dependency on a table and a dependency on its
4147+
* data, so that closer analysis would be needed here.
41454148
*/
41464149
lockids = (DumpId *) pg_malloc(te->nDeps * sizeof(DumpId));
41474150
nlockids = 0;
@@ -4150,7 +4153,8 @@ identify_locking_dependencies(ArchiveHandle *AH, TocEntry *te)
41504153
DumpId depid = te->dependencies[i];
41514154

41524155
if (depid <= AH->maxDumpId && AH->tocsByDumpId[depid] != NULL &&
4153-
strcmp(AH->tocsByDumpId[depid]->desc, "TABLE DATA") == 0)
4156+
((strcmp(AH->tocsByDumpId[depid]->desc, "TABLE DATA") == 0) ||
4157+
strcmp(AH->tocsByDumpId[depid]->desc, "TABLE") == 0))
41544158
lockids[nlockids++] = depid;
41554159
}
41564160

0 commit comments

Comments
 (0)