@@ -7256,6 +7256,7 @@ getTables(Archive *fout, int *numTables)
72567256 int i;
72577257 PQExpBuffer query = createPQExpBuffer();
72587258 TableInfo *tblinfo;
7259+ bool lockTableDumped = false;
72597260 int i_reltableoid;
72607261 int i_reloid;
72617262 int i_relname;
@@ -7963,6 +7964,8 @@ getTables(Archive *fout, int *numTables)
79637964 ExecuteSqlStatement(fout, query->data);
79647965 }
79657966
7967+ resetPQExpBuffer(query);
7968+
79667969 for (i = 0; i < ntups; i++)
79677970 {
79687971 tblinfo[i].dobj.objType = DO_TABLE;
@@ -8098,6 +8101,11 @@ getTables(Archive *fout, int *numTables)
80988101 *
80998102 * We only need to lock the table for certain components; see
81008103 * 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.
81018109 */
81028110 /* GPDB_14_MERGE_FIXME: GPDB_96_MERGE_FIXME: Is the parrelid check still needed? */
81038111 if (tblinfo[i].dobj.dump &&
@@ -8106,18 +8114,29 @@ getTables(Archive *fout, int *numTables)
81068114 tblinfo[i].parrelid == 0 &&
81078115 (tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK))
81088116 {
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;
81148126 }
81158127
81168128 /* Emit notice if join for owner failed */
81178129 if (strlen(tblinfo[i].rolname) == 0)
81188130 pg_log_warning("owner of table \"%s\" appears to be invalid",
81198131 tblinfo[i].dobj.name);
81208132 }
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+ }
81218140
81228141 if (dopt->lockWaitTimeout)
81238142 {
0 commit comments