]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Change pg_restore -f- to dump to stdout instead of to ./-
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 5 Nov 2019 13:08:55 +0000 (10:08 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 5 Nov 2019 13:08:55 +0000 (10:08 -0300)
Starting with PostgreSQL 12, pg_restore refuses to run when neither -d
nor -f are specified (c.f. commit 413ccaa74d9a), and it also makes "-f -"
mean the old implicit behavior of dumping to stdout.  However, older
branches write to a file called ./- when invoked like that, making it
impossible to write pg_restore scripts that work across versions.  This
is a partial backpatch of the aforementioned commit to all older
supported branches, providing an upgrade path.

Discussion: https://postgr.es/m/20191006190839.GE18030@telsasoft.com

doc/src/sgml/ref/pg_restore.sgml
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_restore.c

index 5180103526097c21468cba46adf7c73072116af4..474d2bef66e010f80023d3b5722be9c5819c758d 100644 (file)
       <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 <literal>-</literal>
+        for the standard output, which is also the default.
        </para>
       </listitem>
      </varlistentry>
index a68458fa91bc325f7dc533d3fbefc62e2677e8f7..506e89109937482cbf2df811ce0711b458ffc2df 100644 (file)
@@ -1523,7 +1523,12 @@ SetOutput(ArchiveHandle *AH, const char *filename, int compression)
        int                     fn;
 
        if (filename)
-               fn = -1;
+       {
+               if (strcmp(filename, "-") == 0)
+                       fn = fileno(stdout);
+               else
+                       fn = -1;
+       }
        else if (AH->FH)
                fn = fileno(AH->FH);
        else if (AH->fSpec)
index 88f11740ea6d08c9a537976f204e9ab8f2e34f64..13854ad2ce172e6fee510c0d211daa053dc56c9c 100644 (file)
@@ -451,7 +451,7 @@ usage(const char *progname)
 
        printf(_("\nGeneral options:\n"));
        printf(_("  -d, --dbname=NAME        connect to database name\n"));
-       printf(_("  -f, --file=FILENAME      output file name\n"));
+       printf(_("  -f, --file=FILENAME      output file name (- for stdout)\n"));
        printf(_("  -F, --format=c|d|t       backup file format (should be automatic)\n"));
        printf(_("  -l, --list               print summarized TOC of the archive\n"));
        printf(_("  -v, --verbose            verbose mode\n"));