Skip to content

Commit 6c320b8

Browse files
committed
Obtain table locks as soon as practical during pg_dump.
For some reason, when we (I) added table lock acquisition to pg_dump, we didn't think about making it happen as soon as possible after the start of the transaction. What with subsequent additions, there was actually quite a lot going on before we got around to that; which sort of defeats the purpose. Rearrange the order of calls in dumpSchema() to close the risk window as much as we easily can. Back-patch to all supported branches.
1 parent 199d449 commit 6c320b8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/bin/pg_dump/common.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ getSchemaData(int *numTablesPtr)
9191
write_msg(NULL, "reading schemas\n");
9292
nsinfo = getNamespaces(&numNamespaces);
9393

94+
/*
95+
* getTables should be done as soon as possible, so as to minimize the
96+
* window between starting our transaction and acquiring per-table locks.
97+
* However, we have to do getNamespaces first because the tables get
98+
* linked to their containing namespaces during getTables.
99+
*/
100+
if (g_verbose)
101+
write_msg(NULL, "reading user-defined tables\n");
102+
tblinfo = getTables(&numTables);
103+
94104
if (g_verbose)
95105
write_msg(NULL, "reading user-defined functions\n");
96106
funinfo = getFuncs(&numFuncs);
@@ -121,10 +131,6 @@ getSchemaData(int *numTablesPtr)
121131
write_msg(NULL, "reading user-defined conversions\n");
122132
convinfo = getConversions(&numConversions);
123133

124-
if (g_verbose)
125-
write_msg(NULL, "reading user-defined tables\n");
126-
tblinfo = getTables(&numTables);
127-
128134
if (g_verbose)
129135
write_msg(NULL, "reading table inheritance information\n");
130136
inhinfo = getInherits(&numInherits);

0 commit comments

Comments
 (0)