Em seg, 18 de fev de 2019 às 19:21, Tom Lane <t...@sss.pgh.pa.us> escreveu: > > Euler Taveira <eu...@timbira.com.br> writes: > > Since no one has stepped up, I took a stab at it. It will prohibit > > standard output unless '-f -' be specified. -l option also has the > > same restriction. > > Hm, don't really see the need to break -l usage here. > After thinking about it, revert it.
> Pls add to next CF, if you didn't already. > Done. -- Euler Taveira Timbira - http://www.timbira.com.br/ PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento
From a0f84d0dd7148e8a167972e76ddbf2e05f20ca9d Mon Sep 17 00:00:00 2001 From: Euler Taveira <eu...@timbira.com.br> Date: Sun, 17 Feb 2019 14:16:27 +0000 Subject: [PATCH] pg_restore supports stdout in --file pg_restore defaults to standard output if neither -f nor -d is specified. This behavior confuses users that expect an error if the restore target (database or file) isn't specified. Other clients already support '-f -' but pg_restore does not. This change breaks backward compatibility because it errors out if neither -f nor -d is specified and '-f -' doesn't create a file called '-' instead it outputs to standard output. Discussion: https://www.postgresql.org/message-id/87sgwrmhdv....@news-spur.riddles.org.uk --- doc/src/sgml/ref/pg_restore.sgml | 4 ++-- src/bin/pg_dump/pg_backup_archiver.c | 4 +++- src/bin/pg_dump/pg_restore.c | 7 +++++++ src/bin/pg_dump/t/001_basic.pl | 14 +++++++------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml index 725acb1..c8c4c20 100644 --- a/doc/src/sgml/ref/pg_restore.sgml +++ b/doc/src/sgml/ref/pg_restore.sgml @@ -176,8 +176,8 @@ <listitem> <para> Specify output file for generated script, or for the listing - when used with <option>-l</option>. Default is the standard - output. + when used with <option>-l</option>. Use <option>-f</option> + <literal>-</literal> for <systemitem>stdout</systemitem>. </para> </listitem> </varlistentry> diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 8b55f59..e6b8b6a 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -1517,7 +1517,9 @@ SetOutput(ArchiveHandle *AH, const char *filename, int compression) { int fn; - if (filename) + if (filename && strcmp(filename, "-") == 0) + fn = fileno(stdout); + else if (filename) fn = -1; else if (AH->FH) fn = fileno(AH->FH); diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 428e040..21cd6da 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -303,6 +303,13 @@ main(int argc, char **argv) exit_nicely(1); } + /* Complain if neither -f nor -d was specified (this restriction is not valid for TOC) */ + if (!opts->dbname && !opts->filename && !opts->tocSummary) + { + fprintf(stderr, _("%s: option -d/--dbname or -f/--file should be specified\n"), progname); + exit_nicely(1); + } + /* Should get at most one of -d and -f, else user is confused */ if (opts->dbname) { diff --git a/src/bin/pg_dump/t/001_basic.pl b/src/bin/pg_dump/t/001_basic.pl index a875d54..0cfda48 100644 --- a/src/bin/pg_dump/t/001_basic.pl +++ b/src/bin/pg_dump/t/001_basic.pl @@ -50,7 +50,7 @@ command_fails_like( ); command_fails_like( - [ 'pg_restore', '-s', '-a' ], + [ 'pg_restore', '-s', '-a', '-f -' ], qr/\Qpg_restore: options -s\/--schema-only and -a\/--data-only cannot be used together\E/, 'pg_restore: options -s/--schema-only and -a/--data-only cannot be used together' ); @@ -66,7 +66,7 @@ command_fails_like( 'pg_dump: options -c/--clean and -a/--data-only cannot be used together'); command_fails_like( - [ 'pg_restore', '-c', '-a' ], + [ 'pg_restore', '-c', '-a', '-f -' ], qr/\Qpg_restore: options -c\/--clean and -a\/--data-only cannot be used together\E/, 'pg_restore: options -c/--clean and -a/--data-only cannot be used together' ); @@ -92,12 +92,12 @@ command_fails_like( 'pg_dump: invalid output format'); command_fails_like( - [ 'pg_restore', '-j', '-1' ], + [ 'pg_restore', '-j', '-1', '-f -' ], qr/\Qpg_restore: invalid number of parallel jobs\E/, 'pg_restore: invalid number of parallel jobs'); command_fails_like( - [ 'pg_restore', '--single-transaction', '-j3' ], + [ 'pg_restore', '--single-transaction', '-j3', '-f -' ], qr/\Qpg_restore: cannot specify both --single-transaction and multiple jobs\E/, 'pg_restore: cannot specify both --single-transaction and multiple jobs'); @@ -107,12 +107,12 @@ command_fails_like( 'pg_dump: compression level must be in range 0..9'); command_fails_like( - [ 'pg_restore', '--if-exists' ], + [ 'pg_restore', '--if-exists', '-f -' ], qr/\Qpg_restore: option --if-exists requires option -c\/--clean\E/, 'pg_restore: option --if-exists requires option -c/--clean'); command_fails_like( - [ 'pg_restore', '-F', 'garbage' ], + [ 'pg_restore', '-f -', '-F', 'garbage' ], qr/\Qpg_restore: unrecognized archive format "garbage";\E/, 'pg_dump: unrecognized archive format'); @@ -146,7 +146,7 @@ command_fails_like( 'pg_dumpall: option --if-exists requires option -c/--clean'); command_fails_like( - [ 'pg_restore', '-C', '-1' ], + [ 'pg_restore', '-C', '-1', '-f -' ], qr/\Qpg_restore: options -C\/--create and -1\/--single-transaction cannot be used together\E/, 'pg_restore: options -C\/--create and -1\/--single-transaction cannot be used together' ); -- 2.7.4