Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4b5f399

Browse files
committed
pg_restore: Don't allow non-positive number of jobs
pg_restore will currently accept invalid values for the number of parallel jobs to run (eg: -1), unlike pg_dump which does check that the value provided is reasonable. Worse, '-1' is actually a valid, independent, parameter (as an alias for --single-transaction), leading to potentially completely unexpected results from a command line such as: -> pg_restore -j -1 Where a user would get neither parallel jobs nor a single-transaction. Add in validity checking of the parallel jobs option, as we already have in pg_dump, before we try to open up the archive. Also move the check that we haven't been asked to run more parallel jobs than possible on Windows to the same place, so we do all the option validity checking before opening the archive. Back-patch all the way, though for 9.2 we're adding the Windows-specific check against MAXIMUM_WAIT_OBJECTS as that check wasn't back-patched originally. Discussion: https://www.postgresql.org/message-id/20170110044815.GC18360%40tamriel.snowman.net
1 parent 1c15f84 commit 4b5f399

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/bin/pg_dump/pg_restore.c

+16-10
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,22 @@ main(int argc, char **argv)
325325
exit_nicely(1);
326326
}
327327

328+
if (numWorkers <= 0)
329+
{
330+
fprintf(stderr, _("%s: invalid number of parallel jobs\n"), progname);
331+
exit(1);
332+
}
333+
334+
/* See comments in pg_dump.c */
335+
#ifdef WIN32
336+
if (numWorkers > MAXIMUM_WAIT_OBJECTS)
337+
{
338+
fprintf(stderr, _("%s: maximum number of parallel jobs is %d\n"),
339+
progname, MAXIMUM_WAIT_OBJECTS);
340+
exit(1);
341+
}
342+
#endif
343+
328344
/* Can't do single-txn mode with multiple connections */
329345
if (opts->single_txn && numWorkers > 1)
330346
{
@@ -397,16 +413,6 @@ main(int argc, char **argv)
397413
if (opts->tocFile)
398414
SortTocFromFile(AH);
399415

400-
/* See comments in pg_dump.c */
401-
#ifdef WIN32
402-
if (numWorkers > MAXIMUM_WAIT_OBJECTS)
403-
{
404-
fprintf(stderr, _("%s: maximum number of parallel jobs is %d\n"),
405-
progname, MAXIMUM_WAIT_OBJECTS);
406-
exit(1);
407-
}
408-
#endif
409-
410416
AH->numWorkers = numWorkers;
411417

412418
if (opts->tocSummary)

0 commit comments

Comments
 (0)