mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +03:00
Clean up some minor inefficiencies in parallel dump/restore.
Parallel dump did a totally pointless query to find out the name of each table to be dumped, which it already knows. Parallel restore runs issued lots of redundant SET commands because _doSetFixedOutputState() was invoked once per TOC item rather than just once at connection start. While the extra queries are insignificant if you're dumping or restoring large tables, it still seems worth getting rid of them. Also, give the responsibility for selecting the right client_encoding for a parallel dump worker to setup_connection() where it naturally belongs, instead of having ad-hoc code for that in CloneArchive(). And fix some minor bugs like use of strdup() where pg_strdup() would be safer. Back-patch to 9.3, mostly to keep the branches in sync in an area that we're still finding bugs in. Discussion: <5086.1464793073@sss.pgh.pa.us>
This commit is contained in:
@@ -3831,6 +3831,7 @@ restore_toc_entries_postfork(ArchiveHandle *AH, TocEntry *pending_list)
|
||||
ropt->pghost, ropt->pgport, ropt->username,
|
||||
ropt->promptPassword);
|
||||
|
||||
/* re-establish fixed state */
|
||||
_doSetFixedOutputState(AH);
|
||||
|
||||
/*
|
||||
@@ -4009,10 +4010,9 @@ parallel_restore(ParallelArgs *args)
|
||||
TocEntry *te = args->te;
|
||||
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 */
|
||||
@@ -4381,10 +4381,14 @@ CloneArchive(ArchiveHandle *AH)
|
||||
RestoreOptions *ropt = AH->public.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
|
||||
{
|
||||
@@ -4392,7 +4396,6 @@ CloneArchive(ArchiveHandle *AH)
|
||||
char *pghost;
|
||||
char *pgport;
|
||||
char *username;
|
||||
const char *encname;
|
||||
|
||||
Assert(AH->connection != NULL);
|
||||
|
||||
@@ -4406,18 +4409,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 */
|
||||
|
Reference in New Issue
Block a user