Obtain table locks as soon as practical during pg_dump.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Jun 2011 22:19:31 +0000 (18:19 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Jun 2011 22:19:31 +0000 (18:19 -0400)
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.

src/bin/pg_dump/common.c

index 070036ec054fc2e5f93aacf51ab4e2ac7f7781ee..7ea98b396fa6e5891c55686c84508eeb77e0252f 100644 (file)
@@ -91,6 +91,16 @@ getSchemaData(int *numTablesPtr)
        write_msg(NULL, "reading schemas\n");
    nsinfo = 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);
+
    if (g_verbose)
        write_msg(NULL, "reading user-defined functions\n");
    funinfo = getFuncs(&numFuncs);
@@ -121,10 +131,6 @@ getSchemaData(int *numTablesPtr)
        write_msg(NULL, "reading user-defined conversions\n");
    convinfo = getConversions(&numConversions);
 
-   if (g_verbose)
-       write_msg(NULL, "reading user-defined tables\n");
-   tblinfo = getTables(&numTables);
-
    if (g_verbose)
        write_msg(NULL, "reading table inheritance information\n");
    inhinfo = getInherits(&numInherits);