From 9edff69d80ec3f8d4e54aafab357916a7d03ae22 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Sat, 27 Oct 2018 22:41:53 +0200
Subject: [PATCH] Consolidate option checking in pg_restore

Move the check for conflicting options from the archive restore code
to the main function where other similar checks are performed.  Also
reword the error message to be in line with other messages.
---
 src/bin/pg_dump/pg_backup_archiver.c |  9 ---------
 src/bin/pg_dump/pg_restore.c         | 11 +++++++++++
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index e976def42a..defa8a41b7 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -358,15 +358,6 @@ RestoreArchive(Archive *AHX)
 
 	AH->stage = STAGE_INITIALIZING;
 
-	/*
-	 * Check for nonsensical option combinations.
-	 *
-	 * -C is not compatible with -1, because we can't create a database inside
-	 * a transaction block.
-	 */
-	if (ropt->createDB && ropt->single_txn)
-		exit_horribly(modulename, "-C and -1 are incompatible options\n");
-
 	/*
 	 * If we're going to do parallel restore, there are some restrictions.
 	 */
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 501d7cea72..58b36b6bf7 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -331,6 +331,17 @@ main(int argc, char **argv)
 		exit_nicely(1);
 	}
 
+	/*
+	 * -C is not compatible with -1, because we can't create a database inside
+	 * a transaction block.
+	 */
+	if (opts->createDB && opts->single_txn)
+	{
+		fprintf(stderr, _("%s: options -C/--create and -1/--single-transaction cannot be used together\n"),
+				progname);
+		exit_nicely(1);
+	}
+
 	if (numWorkers <= 0)
 	{
 		fprintf(stderr, _("%s: invalid number of parallel jobs\n"), progname);
-- 
2.14.1.145.gb3622a4ee

