aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/pg_dump/parallel.c26
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c18
-rw-r--r--src/bin/pg_dump/pg_dump.c32
3 files changed, 29 insertions, 47 deletions
diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
index 65f3c19221e..04b7015bd7f 100644
--- a/src/bin/pg_dump/parallel.c
+++ b/src/bin/pg_dump/parallel.c
@@ -804,7 +804,6 @@ IsEveryWorkerIdle(ParallelState *pstate)
static void
lockTableForWorker(ArchiveHandle *AH, TocEntry *te)
{
- Archive *AHX = (Archive *) AH;
const char *qualId;
PQExpBuffer query;
PGresult *res;
@@ -815,33 +814,10 @@ lockTableForWorker(ArchiveHandle *AH, TocEntry *te)
query = createPQExpBuffer();
- /*
- * XXX this is an unbelievably expensive substitute for knowing how to dig
- * a table name out of a TocEntry.
- */
- appendPQExpBuffer(query,
- "SELECT pg_namespace.nspname,"
- " pg_class.relname "
- " FROM pg_class "
- " JOIN pg_namespace on pg_namespace.oid = relnamespace "
- " WHERE pg_class.oid = %u", te->catalogId.oid);
-
- res = PQexec(AH->connection, query->data);
-
- if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
- exit_horribly(modulename,
- "could not get relation name for OID %u: %s\n",
- te->catalogId.oid, PQerrorMessage(AH->connection));
-
- resetPQExpBuffer(query);
-
- qualId = fmtQualifiedId(AHX->remoteVersion,
- PQgetvalue(res, 0, 0),
- PQgetvalue(res, 0, 1));
+ qualId = fmtQualifiedId(AH->public.remoteVersion, te->namespace, te->tag);
appendPQExpBuffer(query, "LOCK TABLE %s IN ACCESS SHARE MODE NOWAIT",
qualId);
- PQclear(res);
res = PQexec(AH->connection, query->data);
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 036a1e576bd..52aebc4735d 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -3729,6 +3729,7 @@ restore_toc_entries_postfork(ArchiveHandle *AH, TocEntry *pending_list)
ropt->pghost, ropt->pgport, ropt->username,
ropt->promptPassword);
+ /* re-establish fixed state */
_doSetFixedOutputState(AH);
/*
@@ -3908,10 +3909,9 @@ parallel_restore(ParallelArgs *args)
RestoreOptions *ropt = AH->ropt;
int status;
- _doSetFixedOutputState(AH);
-
Assert(AH->connection != NULL);
+ /* Count only errors associated with this TOC entry */
AH->public.n_errors = 0;
/* Restore the TOC item */
@@ -4280,10 +4280,14 @@ CloneArchive(ArchiveHandle *AH)
RestoreOptions *ropt = AH->ropt;
Assert(AH->connection == NULL);
+
/* this also sets clone->connection */
ConnectDatabase((Archive *) clone, ropt->dbname,
ropt->pghost, ropt->pgport, ropt->username,
ropt->promptPassword);
+
+ /* re-establish fixed state */
+ _doSetFixedOutputState(clone);
}
else
{
@@ -4291,7 +4295,6 @@ CloneArchive(ArchiveHandle *AH)
char *pghost;
char *pgport;
char *username;
- const char *encname;
Assert(AH->connection != NULL);
@@ -4305,18 +4308,11 @@ CloneArchive(ArchiveHandle *AH)
pghost = PQhost(AH->connection);
pgport = PQport(AH->connection);
username = PQuser(AH->connection);
- encname = pg_encoding_to_char(AH->public.encoding);
/* this also sets clone->connection */
ConnectDatabase((Archive *) clone, dbname, pghost, pgport, username, TRI_NO);
- /*
- * Set the same encoding, whatever we set here is what we got from
- * pg_encoding_to_char(), so we really shouldn't run into an error
- * setting that very same value. Also see the comment in
- * SetupConnection().
- */
- PQsetClientEncoding(clone->connection, encname);
+ /* setupDumpWorker will fix up connection state */
}
/* Let the format-specific code have a chance too */
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 7af49750948..8e62aea9f54 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -950,10 +950,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
const char *std_strings;
/*
- * Set the client encoding if requested. If dumpencoding == NULL then
- * either it hasn't been requested or we're a cloned connection and then
- * this has already been set in CloneArchive according to the original
- * connection encoding.
+ * Set the client encoding if requested.
*/
if (dumpencoding)
{
@@ -971,7 +968,11 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
std_strings = PQparameterStatus(conn, "standard_conforming_strings");
AH->std_strings = (std_strings && strcmp(std_strings, "on") == 0);
- /* Set the role if requested */
+ /*
+ * Set the role if requested. In a parallel dump worker, we'll be passed
+ * use_role == NULL, but AH->use_role is already set (if user specified it
+ * originally) and we should use that.
+ */
if (!use_role && AH->use_role)
use_role = AH->use_role;
@@ -984,9 +985,9 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
ExecuteSqlStatement(AH, query->data);
destroyPQExpBuffer(query);
- /* save this for later use on parallel connections */
+ /* save it for possible later use by parallel workers */
if (!AH->use_role)
- AH->use_role = strdup(use_role);
+ AH->use_role = pg_strdup(use_role);
}
/* Set the datestyle to ISO to ensure the dump's portability */
@@ -1078,21 +1079,30 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
}
}
+/* Set up connection for a parallel worker process */
static void
-setupDumpWorker(Archive *AHX, RestoreOptions *ropt)
+setupDumpWorker(Archive *AH, RestoreOptions *ropt)
{
- setup_connection(AHX, NULL, NULL);
+ /*
+ * We want to re-select all the same values the master connection is
+ * using. We'll have inherited directly-usable values in
+ * AH->sync_snapshot_id and AH->use_role, but we need to translate the
+ * inherited encoding value back to a string to pass to setup_connection.
+ */
+ setup_connection(AH,
+ pg_encoding_to_char(AH->encoding),
+ NULL);
}
static char *
get_synchronized_snapshot(Archive *fout)
{
- char *query = "SELECT pg_export_snapshot()";
+ char *query = "SELECT pg_catalog.pg_export_snapshot()";
char *result;
PGresult *res;
res = ExecuteSqlQueryForSingleRow(fout, query);
- result = strdup(PQgetvalue(res, 0, 0));
+ result = pg_strdup(PQgetvalue(res, 0, 0));
PQclear(res);
return result;