1 /*-------------------------------------------------------------------------
6 * Copyright (c) 2010-2016, PostgreSQL Global Development Group
8 *-------------------------------------------------------------------------
10 #include "postgres_fe.h"
15 #include "pg_rewind.h"
20 /* Progress counters */
24 static pg_time_t last_progress_report = 0;
26 #define QUERY_ALLOC 8192
28 #define MESSAGE_WIDTH 60
31 pg_attribute_printf(2, 0)
33 pg_log_v(eLogType type, const char *fmt, va_list ap)
35 char message[QUERY_ALLOC];
37 vsnprintf(message, sizeof(message), fmt, ap);
43 printf("%s", _(message));
48 printf("%s", _(message));
52 printf("%s", _(message));
56 printf("\n%s", _(message));
57 printf("%s", _("Failure, exiting\n"));
69 pg_log(eLogType type, const char *fmt,...)
74 pg_log_v(type, fmt, args);
80 * Print an error message, and exit.
83 pg_fatal(const char *fmt,...)
88 pg_log_v(PG_FATAL, fmt, args);
90 /* should not get here, pg_log_v() exited already */
96 * Print a progress report based on the global variables.
98 * Progress report is written at maximum once per second, unless the
99 * force parameter is set to true.
102 progress_report(bool force)
105 char fetch_done_str[32];
106 char fetch_size_str[32];
113 if (now == last_progress_report && !force)
114 return; /* Max once per second */
116 last_progress_report = now;
117 percent = fetch_size ? (int) ((fetch_done) * 100 / fetch_size) : 0;
120 * Avoid overflowing past 100% or the full size. This may make the total
121 * size number change as we approach the end of the backup (the estimate
122 * will always be wrong if WAL is included), but that's better than having
123 * the done column be bigger than the total.
127 if (fetch_done > fetch_size)
128 fetch_size = fetch_done;
131 * Separate step to keep platform-dependent format code out of
132 * translatable strings. And we only test for INT64_FORMAT availability
133 * in snprintf, not fprintf.
135 snprintf(fetch_done_str, sizeof(fetch_done_str), INT64_FORMAT,
137 snprintf(fetch_size_str, sizeof(fetch_size_str), INT64_FORMAT,
140 pg_log(PG_PROGRESS, "%*s/%s kB (%d%%) copied",
141 (int) strlen(fetch_size_str), fetch_done_str, fetch_size_str,