aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2017-01-11 15:45:56 -0500
committerStephen Frost <sfrost@snowman.net>2017-01-11 15:45:56 -0500
commit26e7cdb3a80d340742aeb5bfe2dbc42edfb9d34b (patch)
treecea8013f2b10f70a33624f4bb1f0b1866186ff4b /src
parentf12681079020eea53ea9a0eb994ac2ee6190770f (diff)
downloadpostgresql-26e7cdb3a80d340742aeb5bfe2dbc42edfb9d34b.tar.gz
postgresql-26e7cdb3a80d340742aeb5bfe2dbc42edfb9d34b.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_restore.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 2b209027f56..f9fb12c2d6b 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -323,6 +323,22 @@ main(int argc, char **argv)
exit_nicely(1);
}
+ if (numWorkers <= 0)
+ {
+ fprintf(stderr, _("%s: invalid number of parallel jobs\n"), progname);
+ exit(1);
+ }
+
+ /* See comments in pg_dump.c */
+#ifdef WIN32
+ if (numWorkers > MAXIMUM_WAIT_OBJECTS)
+ {
+ fprintf(stderr, _("%s: maximum number of parallel jobs is %d\n"),
+ progname, MAXIMUM_WAIT_OBJECTS);
+ exit(1);
+ }
+#endif
+
/* Can't do single-txn mode with multiple connections */
if (opts->single_txn && numWorkers > 1)
{
@@ -394,16 +410,6 @@ main(int argc, char **argv)
if (opts->tocFile)
SortTocFromFile(AH);
- /* See comments in pg_dump.c */
-#ifdef WIN32
- if (numWorkers > MAXIMUM_WAIT_OBJECTS)
- {
- fprintf(stderr, _("%s: maximum number of parallel jobs is %d\n"),
- progname, MAXIMUM_WAIT_OBJECTS);
- exit(1);
- }
-#endif
-
AH->numWorkers = numWorkers;
if (opts->tocSummary)