Re: Option to dump foreign data in pg_dump

Alvaro Herrera <alvherre@2ndquadrant.com>

From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: Luis Carril <luis.carril@swarm64.com>, vignesh C <vignesh21@gmail.com>, Daniel Gustafsson <daniel@yesql.se>, Laurenz Albe <laurenz.albe@cybertec.at>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-03-23T20:17:13Z
Lists: 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



Commits

  1. pg_dump: Allow dumping data of specific foreign servers