Skip to content

Commit adb103f

Browse files
committed
pgbench: Ensure previous progress message is fully cleared when updating.
During pgbench's table initialization, progress updates could display leftover characters from the previous message if the new message was shorter. This commit resolves the issue by appending spaces to the current message to fully overwrite any remaining characters from the previous line. Back-patch to all the supported versions. Author: Yushi Ogiwara, Tatsuo Ishii, Fujii Masao Reviewed-by: Tatsuo Ishii, Fujii Masao Discussion: https://postgr.es/m/9a9b8b95b6a709877ae48ad5b0c59bb9@oss.nttdata.com
1 parent 6e79358 commit adb103f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/bin/pgbench/pgbench.c

+16-5
Original file line numberDiff line numberDiff line change
@@ -4943,6 +4943,7 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
49434943
int n;
49444944
int64 k;
49454945
int chars = 0;
4946+
int prev_chars = 0;
49464947
PGresult *res;
49474948
PQExpBufferData sql;
49484949
char copy_statement[256];
@@ -5003,10 +5004,10 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
50035004
double elapsed_sec = PG_TIME_GET_DOUBLE(pg_time_now() - start);
50045005
double remaining_sec = ((double) total - j) * elapsed_sec / j;
50055006

5006-
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)%c",
5007+
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)",
50075008
j, total,
50085009
(int) ((j * 100) / total),
5009-
table, elapsed_sec, remaining_sec, eol);
5010+
table, elapsed_sec, remaining_sec);
50105011
}
50115012
/* let's not call the timing for each row, but only each 100 rows */
50125013
else if (use_quiet && (j % 100 == 0))
@@ -5017,19 +5018,29 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
50175018
/* have we reached the next interval (or end)? */
50185019
if ((j == total) || (elapsed_sec >= log_interval * LOG_STEP_SECONDS))
50195020
{
5020-
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)%c",
5021+
chars = fprintf(stderr, INT64_FORMAT " of " INT64_FORMAT " tuples (%d%%) of %s done (elapsed %.2f s, remaining %.2f s)",
50215022
j, total,
50225023
(int) ((j * 100) / total),
5023-
table, elapsed_sec, remaining_sec, eol);
5024+
table, elapsed_sec, remaining_sec);
50245025

50255026
/* skip to the next interval */
50265027
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);
50275028
}
50285029
}
5030+
5031+
/*
5032+
* If the previous progress message is longer than the current one,
5033+
* add spaces to the current line to fully overwrite any remaining
5034+
* characters from the previous message.
5035+
*/
5036+
if (prev_chars > chars)
5037+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
5038+
fputc(eol, stderr);
5039+
prev_chars = chars;
50295040
}
50305041

50315042
if (chars != 0 && eol != '\n')
5032-
fprintf(stderr, "%*c\r", chars - 1, ' '); /* Clear the current line */
5043+
fprintf(stderr, "%*c\r", chars, ' '); /* Clear the current line */
50335044

50345045
if (PQputline(con, "\\.\n"))
50355046
pg_fatal("very last PQputline failed");

0 commit comments

Comments
 (0)