mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +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:
@@ -801,7 +801,6 @@ IsEveryWorkerIdle(ParallelState *pstate)
|
||||
static void
|
||||
lockTableForWorker(ArchiveHandle *AH, TocEntry *te)
|
||||
{
|
||||
Archive *AHX = (Archive *) AH;
|
||||
const char *qualId;
|
||||
PQExpBuffer query;
|
||||
PGresult *res;
|
||||
@@ -812,33 +811,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);
|
||||
|
||||
|
Reference in New Issue
Block a user