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

Commit c34bca9

Browse files
committed
Consolidate cross-option checks in pg_restore
This moves one 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 consistent with other messages. The only option combination impacted is --create specified with --single-transaction, and informing the caller at an early step saves from opening the archive worked on. A TAP test is added for this combination. Author: Daniel Gustafsson Reviewed-by: Fabien Coelho Discussion: https://postgr.es/m/616808BD-4B59-4E6C-97A9-7317F62D5570@yesql.se
1 parent d5eec4e commit c34bca9

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/bin/pg_dump/pg_backup_archiver.c

-9
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,6 @@ RestoreArchive(Archive *AHX)
358358

359359
AH->stage = STAGE_INITIALIZING;
360360

361-
/*
362-
* Check for nonsensical option combinations.
363-
*
364-
* -C is not compatible with -1, because we can't create a database inside
365-
* a transaction block.
366-
*/
367-
if (ropt->createDB && ropt->single_txn)
368-
exit_horribly(modulename, "-C and -1 are incompatible options\n");
369-
370361
/*
371362
* If we're going to do parallel restore, there are some restrictions.
372363
*/

src/bin/pg_dump/pg_restore.c

+11
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,17 @@ main(int argc, char **argv)
331331
exit_nicely(1);
332332
}
333333

334+
/*
335+
* -C is not compatible with -1, because we can't create a database inside
336+
* a transaction block.
337+
*/
338+
if (opts->createDB && opts->single_txn)
339+
{
340+
fprintf(stderr, _("%s: options -C/--create and -1/--single-transaction cannot be used together\n"),
341+
progname);
342+
exit_nicely(1);
343+
}
344+
334345
if (numWorkers <= 0)
335346
{
336347
fprintf(stderr, _("%s: invalid number of parallel jobs\n"), progname);

src/bin/pg_dump/t/001_basic.pl

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Config;
55
use PostgresNode;
66
use TestLib;
7-
use Test::More tests => 70;
7+
use Test::More tests => 72;
88

99
my $tempdir = TestLib::tempdir;
1010
my $tempdir_short = TestLib::tempdir_short;
@@ -150,3 +150,9 @@
150150
[ 'pg_dumpall', '--if-exists' ],
151151
qr/\Qpg_dumpall: option --if-exists requires option -c\/--clean\E/,
152152
'pg_dumpall: option --if-exists requires option -c/--clean');
153+
154+
command_fails_like(
155+
[ 'pg_restore', '-C', '-1' ],
156+
qr/\Qpg_restore: options -C\/--create and -1\/--single-transaction cannot be used together\E/,
157+
'pg_restore: options -C\/--create and -1\/--single-transaction cannot be used together'
158+
);

0 commit comments

Comments
 (0)