8000 pg_restore: Don't allow non-positive number of jobs · hackingwu/postgres@4779d6c · GitHub
[go: up one dir, main page]

Skip to content

Commit 4779d6c

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 7cda702 commit 4779d6c

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/bin/pg_dump/pg_restore.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,22 @@ main(int argc, char **argv)
314314
opts->useDB = 1;
315315
}
316316

317+
if (numWorkers <= 0)
318+
{
319+
fprintf(stderr, _("%s: invalid number of parallel jobs\n"), progname);
320+
exit(1);
321+
}
322+
323+
/* See comments in pg_dump.c */
324+
#ifdef WIN32
325+
if (numWorkers > MAXIMUM_WAIT_OBJECTS)
326+
{
327+
fprintf(stderr, _("%s: maximum number of parallel jobs is %d\n"),
328+
progname, MAXIMUM_WAIT_OBJECTS);
329+
exit(1);
330+
}
331+
#endif
332+
317333
/* Can't do single-txn mode with multiple connections */
318334
if (opts->single_txn && numWorkers > 1)
319335
{
@@ -374,16 +390,6 @@ main(int argc, char **argv)
374390
if (opts->tocFile)
375391
SortTocFromFile(AH, opts);
376392

377-
/* See comments in pg_dump.c */
378-
#ifdef WIN32
379-
if (numWorkers > MAXIMUM_WAIT_OBJECTS)
380-
{
381-
fprintf(stderr, _("%s: maximum number of parallel jobs is %d\n"),
382-
progname, MAXIMUM_WAIT_OBJECTS);
383-
exit(1);
384-
}
385-
#endif
386-
387393
AH->numWorkers = numWorkers;
388394

389395
if (opts->tocSummary)

0 commit comments

Comments
 (0)
0