Skip to content

Commit 143b54d

Browse files
committed
pg_basebackup: Fix progress messages when writing to a file
The progress messages print out \r to keep overwriting the same line on the screen. But this does not yield useful results when writing the output to a file. So in that case, print out \n instead. Author: Martín Marqués <martin@2ndquadrant.com> Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
1 parent 06ae669 commit 143b54d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,10 @@ progress_report(int tablespacenum, const char *filename, bool force)
811811
totaldone_str, totalsize_str, percent,
812812
tablespacenum, tablespacecount);
813813

814-
fprintf(stderr, "\r");
814+
if (isatty(fileno(stderr)))
815+
fprintf(stderr, "\r");
816+
else
817+
fprintf(stderr, "\n");
815818
}
816819

817820
static int32
@@ -1796,7 +1799,13 @@ BaseBackup(void)
17961799
progname);
17971800

17981801
if (showprogress && !verbose)
1799-
fprintf(stderr, "waiting for checkpoint\r");
1802+
{
1803+
fprintf(stderr, "waiting for checkpoint");
1804+
if (isatty(fileno(stderr)))
1805+
fprintf(stderr, "\r");
1806+
else
1807+
fprintf(stderr, "\n");
1808+
}
18001809

18011810
basebkp =
18021811
psprintf("BASE_BACKUP LABEL '%s' %s %s %s %s %s %s",
@@ -1929,7 +1938,8 @@ BaseBackup(void)
19291938
if (showprogress)
19301939
{
19311940
progress_report(PQntuples(res), NULL, true);
1932-
fprintf(stderr, "\n"); /* Need to move to next line */
1941+
if (isatty(fileno(stderr)))
1942+
fprintf(stderr, "\n"); /* Need to move to next line */
19331943
}
19341944

19351945
PQclear(res);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy