diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
index c419c2d18063a08d6b3c3c8a922c643a592ae795..a631f64c36f4768031b5beb3198a03921939f3c4 100644
--- a/src/bin/pg_dump/common.c
+++ b/src/bin/pg_dump/common.c
@@ -105,6 +105,17 @@ getSchemaData(int *numTablesPtr)
 		write_msg(NULL, "reading schemas\n");
 	getNamespaces(&numNamespaces);
 
+	/*
+	 * getTables should be done as soon as possible, so as to minimize the
+	 * window between starting our transaction and acquiring per-table locks.
+	 * However, we have to do getNamespaces first because the tables get
+	 * linked to their containing namespaces during getTables.
+	 */
+	if (g_verbose)
+		write_msg(NULL, "reading user-defined tables\n");
+	tblinfo = getTables(&numTables);
+	tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
+
 	if (g_verbose)
 		write_msg(NULL, "reading extensions\n");
 	extinfo = getExtensions(&numExtensions);
@@ -183,11 +194,6 @@ getSchemaData(int *numTablesPtr)
 		write_msg(NULL, "reading type casts\n");
 	getCasts(&numCasts);
 
-	if (g_verbose)
-		write_msg(NULL, "reading user-defined tables\n");
-	tblinfo = getTables(&numTables);
-	tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
-
 	if (g_verbose)
 		write_msg(NULL, "reading table inheritance information\n");
 	inhinfo = getInherits(&numInherits);