Skip to content

Commit e2841d3

Browse files
committed
Make pg_restore's identify_locking_dependencies() more bulletproof.
This function had a blacklist of dump object types that it believed needed exclusive lock ... but we hadn't maintained that, so that it was missing ROW SECURITY, POLICY, and INDEX ATTACH items, all of which need (or should be treated as needing) exclusive lock. Since the same oversight seems likely in future, let's reverse the sense of the test so that the code has a whitelist of safe object types; better to wrongly assume a command can't be run in parallel than the opposite. Currently the only POST_DATA object type that's safe is CREATE INDEX ... and that list hasn't changed in a long time. Back-patch to 9.5 where RLS came in. Discussion: https://postgr.es/m/11450.1535483506@sss.pgh.pa.us
1 parent 64eed26 commit e2841d3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4541,16 +4541,24 @@ identify_locking_dependencies(ArchiveHandle *AH, TocEntry *te)
45414541
int nlockids;
45424542
int i;
45434543

4544+
/*
4545+
* We only care about this for POST_DATA items. PRE_DATA items are not
4546+
* run in parallel, and DATA items are all independent by assumption.
4547+
*/
4548+
if (te->section != SECTION_POST_DATA)
4549+
return;
4550+
45444551
/* Quick exit if no dependencies at all */
45454552
if (te->nDeps == 0)
45464553
return;
45474554

4548-
/* Exit if this entry doesn't need exclusive lock on other objects */
4549-
if (!(strcmp(te->desc, "CONSTRAINT") == 0 ||
4550-
strcmp(te->desc, "CHECK CONSTRAINT") == 0 ||
4551-
strcmp(te->desc, "FK CONSTRAINT") == 0 ||
4552-
strcmp(te->desc, "RULE") == 0 ||
4553-
strcmp(te->desc, "TRIGGER") == 0))
4555+
/*
4556+
* Most POST_DATA items are ALTER TABLEs or some moral equivalent of that,
4557+
* and hence require exclusive lock. However, we know that CREATE INDEX
4558+
* does not. (Maybe someday index-creating CONSTRAINTs will fall in that
4559+
* category too ... but today is not that day.)
4560+
*/
4561+
if (strcmp(te->desc, "INDEX") == 0)
45544562
return;
45554563

45564564
/*

0 commit comments

Comments
 (0)