#include "libpq-fe.h"
#include "pqexpbuffer.h"
#include "pgtar.h"
+#include "pgtime.h"
#include <unistd.h>
#include <dirent.h>
static bool fastcheckpoint = false;
static bool writerecoveryconf = false;
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
+static pg_time_t last_progress_report = 0;
/* Progress counters */
static uint64 totalsize;
/* Function headers */
static void usage(void);
static void verify_dir_is_empty_or_create(char *dirname);
-static void progress_report(int tablespacenum, const char *filename);
+static void progress_report(int tablespacenum, const char *filename, bool force);
static void ReceiveTarFile(PGconn *conn, PGresult *res, int rownum);
static void ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum);
/*
* Print a progress report based on the global variables. If verbose output
* is enabled, also print the current file name.
+ *
+ * Progress report is written at maximum once per second, unless the
+ * force parameter is set to true.
*/
static void
-progress_report(int tablespacenum, const char *filename)
+progress_report(int tablespacenum, const char *filename, bool force)
{
- int percent = (int) ((totaldone / 1024) * 100 / totalsize);
+ int percent;
char totaldone_str[32];
char totalsize_str[32];
+ pg_time_t now;
+
+ if (!showprogress)
+ return;
+
+ now = time(NULL);
+ if (now == last_progress_report && !force)
+ return; /* Max once per second */
+
+ last_progress_report = now;
+ percent = totalsize ? (int) ((totaldone / 1024) * 100 / totalsize) : 0;
/*
* Avoid overflowing past 100% or the full size. This may make the total
}
}
totaldone += r;
- if (showprogress)
- progress_report(rownum, filename);
+ progress_report(rownum, filename, false);
} /* while (1) */
+ progress_report(rownum, filename, true);
if (copybuf != NULL)
PQfreemem(copybuf);
disconnect_and_exit(1);
}
totaldone += r;
- if (showprogress)
- progress_report(rownum, filename);
+ progress_report(rownum, filename, false);
current_len_left -= r;
if (current_len_left == 0 && current_padding == 0)
}
} /* continuing data in existing file */
} /* loop over all data blocks */
+ progress_report(rownum, filename, true);
if (file != NULL)
{
tablespacecount = PQntuples(res);
for (i = 0; i < PQntuples(res); i++)
{
- if (showprogress)
- totalsize += atol(PQgetvalue(res, i, 2));
+ totalsize += atol(PQgetvalue(res, i, 2));
/*
* Verify tablespace directories are empty. Don't bother with the
if (showprogress)
{
- progress_report(PQntuples(res), NULL);
+ progress_report(PQntuples(res), NULL, true);
fprintf(stderr, "\n"); /* Need to move to next line */
}
PQclear(res);