Re: Option to dump foreign data in pg_dump - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Option to dump foreign data in pg_dump
Date
Msg-id 20200323201713.GA15029@alvherre.pgsql
Whole thread Raw
In response to Option to dump foreign data in pg_dump  (Luis Carril <luis.carril@swarm64.com>)
List pgsql-hackers
On 2020-Mar-23, Alvaro Herrera wrote:

> > This seems like an overreaction.  The whole point of lockTableForWorker() is
> > to avoid deadlocks, but foreign tables don't have locks, so it's not a
> > problem.  I think you can just skip foreign tables in lockTableForWorker()
> > using the same logic that getTables() uses.
> > 
> > I think parallel data dump would be an especially interesting option when
> > using foreign tables, so it's worth figuring this out.
> 
> I agree it would be nice to implement this, so I tried to implement it.

(Here's patch for this, which of course doesn't compile)

diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
index c25e3f7a88..b3000da409 100644
--- a/src/bin/pg_dump/parallel.c
+++ b/src/bin/pg_dump/parallel.c
@@ -1316,17 +1316,33 @@ IsEveryWorkerIdle(ParallelState *pstate)
  * then we know that somebody else has requested an ACCESS EXCLUSIVE lock and
  * so we have a deadlock.  We must fail the backup in that case.
  */
+#include "pg_dump.h"
+#include "catalog/pg_class_d.h"
 static void
 lockTableForWorker(ArchiveHandle *AH, TocEntry *te)
 {
     const char *qualId;
     PQExpBuffer query;
     PGresult   *res;
+    DumpableObject *obj;
 
     /* Nothing to do for BLOBS */
     if (strcmp(te->desc, "BLOBS") == 0)
         return;
 
+    /*
+     * Nothing to do for foreign tables either, since they don't support LOCK
+     * TABLE.
+     */
+    obj = findObjectByDumpId(te->dumpId);
+    if (obj->objType == DO_TABLE_DATA)
+    {
+        TableInfo *tabinfo = (TableInfo *) obj;
+
+        if (tabinfo->relkind == RELKIND_FOREIGN_TABLE)
+            return;
+    }
+
     query = createPQExpBuffer();
 
     qualId = fmtQualifiedId(te->namespace, te->tag);

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Option to dump foreign data in pg_dump
Next
From: Jeff Davis
Date:
Subject: Re: Additional size of hash table is alway zero for hash aggregates