@@ -7256,6 +7256,7 @@ getTables(Archive *fout, int *numTables)
7256
7256
int i;
7257
7257
PQExpBuffer query = createPQExpBuffer();
7258
7258
TableInfo *tblinfo;
7259
+ bool lockTableDumped = false;
7259
7260
int i_reltableoid;
7260
7261
int i_reloid;
7261
7262
int i_relname;
@@ -7963,6 +7964,8 @@ getTables(Archive *fout, int *numTables)
7963
7964
ExecuteSqlStatement(fout, query->data);
7964
7965
}
7965
7966
7967
+ resetPQExpBuffer(query);
7968
+
7966
7969
for (i = 0; i < ntups; i++)
7967
7970
{
7968
7971
tblinfo[i].dobj.objType = DO_TABLE;
@@ -8098,6 +8101,11 @@ getTables(Archive *fout, int *numTables)
8098
8101
*
8099
8102
* We only need to lock the table for certain components; see
8100
8103
* pg_dump.h
8104
+ *
8105
+ * GPDB: Build a single LOCK TABLE statement to lock all interesting tables.
8106
+ * This is more performant than issuing a separate LOCK TABLE statement for each table,
8107
+ * with considerable savings in FE/BE overhead. It does come at the cost of some increased
8108
+ * memory usage in both FE and BE, which we will be able to tolerate.
8101
8109
*/
8102
8110
/* GPDB_14_MERGE_FIXME: GPDB_96_MERGE_FIXME: Is the parrelid check still needed? */
8103
8111
if (tblinfo[i].dobj.dump &&
@@ -8106,18 +8114,29 @@ getTables(Archive *fout, int *numTables)
8106
8114
tblinfo[i].parrelid == 0 &&
8107
8115
(tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK))
8108
8116
{
8109
- resetPQExpBuffer(query);
8110
- appendPQExpBuffer(query,
8111
- "LOCK TABLE %s IN ACCESS SHARE MODE",
8112
- fmtQualifiedDumpable(&tblinfo[i]));
8113
- ExecuteSqlStatement(fout, query->data);
8117
+ if (!lockTableDumped)
8118
+ appendPQExpBuffer(query,
8119
+ "LOCK TABLE %s ",
8120
+ fmtQualifiedDumpable(&tblinfo[i]));
8121
+ else
8122
+ appendPQExpBuffer(query,
8123
+ ",%s ",
8124
+ fmtQualifiedDumpable(&tblinfo[i]));
8125
+ lockTableDumped = true;
8114
8126
}
8115
8127
8116
8128
/* Emit notice if join for owner failed */
8117
8129
if (strlen(tblinfo[i].rolname) == 0)
8118
8130
pg_log_warning("owner of table \"%s\" appears to be invalid",
8119
8131
tblinfo[i].dobj.name);
8120
8132
}
8133
+ /* Are there any tables to lock? */
8134
+ if (lockTableDumped)
8135
+ {
8136
+ appendPQExpBuffer(query,
8137
+ "IN ACCESS SHARE MODE");
8138
+ ExecuteSqlStatement(fout, query->data);
8139
+ }
8121
8140
8122
8141
if (dopt->lockWaitTimeout)
8123
8142
{
0 commit comments