Skip to content

Commit 9fb25fd

Browse files
committed
Change pg_restore -f- to dump to stdout instead of to ./-
Starting with PostgreSQL 12, pg_restore refuses to run when neither -d nor -f are specified (c.f. commit 413ccaa), 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
1 parent da5cd7a commit 9fb25fd

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@
165165
<listitem>
166166
<para>
167167
Specify output file for generated script, or for the listing
168-
when used with <option>-l</option>. Default is the standard
169-
output.
168+
when used with <option>-l</option>. Use <literal>-</literal>
169+
for the standard output, which is also the default.
170170
</para>
171171
</listitem>
172172
</varlistentry>

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,12 @@ SetOutput(ArchiveHandle *AH, const char *filename, int compression)
14051405
int fn;
14061406

14071407
if (filename)
1408-
fn = -1;
1408+
{
1409+
if (strcmp(filename, "-") == 0)
1410+
fn = fileno(stdout);
1411+
else
1412+
fn = -1;
1413+
}
14091414
else if (AH->FH)
14101415
fn = fileno(AH->FH);
14111416
else if (AH->fSpec)

src/bin/pg_dump/pg_restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ usage(const char *progname)
440440

441441
printf(_("\nGeneral options:\n"));
442442
printf(_(" -d, --dbname=NAME connect to database name\n"));
443-
printf(_(" -f, --file=FILENAME output file name\n"));
443+
printf(_(" -f, --file=FILENAME output file name (- for stdout)\n"));
444444
printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
445445
printf(_(" -l, --list print summarized TOC of the archive\n"));
446446
printf(_(" -v, --verbose verbose mode\n"));

0 commit comments

Comments
 (0)