Skip to content

Commit 5ee8f0f

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 f5efc93 commit 5ee8f0f

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
@@ -1523,7 +1523,12 @@ SetOutput(ArchiveHandle *AH, const char *filename, int compression)
15231523
int fn;
15241524

15251525
if (filename)
1526-
fn = -1;
1526+
{
1527+
if (strcmp(filename, "-") == 0)
1528+
fn = fileno(stdout);
1529+
else
1530+
fn = -1;
1531+
}
15271532
else if (AH->FH)
15281533
fn = fileno(AH->FH);
15291534
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
@@ -451,7 +451,7 @@ usage(const char *progname)
451451

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

0 commit comments

Comments
 (0)