Skip to content

Commit 7975f2b

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 51328d5 commit 7975f2b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/bin/pg_dump/common.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ getSchemaData(int *numTablesPtr)
115115
write_msg(NULL, "reading schemas\n");
116116
nsinfo = getNamespaces(&numNamespaces);
117117

118+
/*
119+
* getTables should be done as soon as possible, so as to minimize the
120+
* window between starting our transaction and acquiring per-table locks.
121+
* However, we have to do getNamespaces first because the tables get
122+
* linked to their containing namespaces during getTables.
123+
*/
124+
if (g_verbose)
125+
write_msg(NULL, "reading user-defined tables\n");
126+
tblinfo = getTables(&numTables);
127+
tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
128+
118129
if (g_verbose)
119130
write_msg(NULL, "reading user-defined functions\n");
120131
funinfo = getFuncs(&numFuncs);
@@ -180,11 +191,6 @@ getSchemaData(int *numTablesPtr)
180191
write_msg(NULL, "reading user-defined conversions\n");
181192
convinfo = getConversions(&numConversions);
182193

183-
if (g_verbose)
184-
write_msg(NULL, "reading user-defined tables\n");
185-
tblinfo = getTables(&numTables);
186-
tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
187-
188194
if (g_verbose)
189195
write_msg(NULL, "reading table inheritance information\n");
190196
inhinfo = getInherits(&numInherits);

0 commit comments

Comments
 (0)