15
15
#include "libpq-fe.h"
16
16
#include "pqexpbuffer.h"
17
17
#include "pgtar.h"
18
+ #include "pgtime.h"
18
19
19
20
#include <unistd.h>
20
21
#include <dirent.h>
@@ -46,6 +47,7 @@ static bool streamwal = false;
46
47
static bool fastcheckpoint = false;
47
48
static bool writerecoveryconf = false;
48
49
static int standby_message_timeout = 10 * 1000 ; /* 10 sec = default */
50
+ static pg_time_t last_progress_report = 0 ;
49
51
50
52
/* Progress counters */
51
53
static uint64 totalsize ;
@@ -75,7 +77,7 @@ static PQExpBuffer recoveryconfcontents = NULL;
75
77
/* Function headers */
76
78
static void usage (void );
77
79
static void verify_dir_is_empty_or_create (char * dirname );
78
- static void progress_report (int tablespacenum , const char * filename );
80
+ static void progress_report (int tablespacenum , const char * filename , bool force );
79
81
80
82
static void ReceiveTarFile (PGconn * conn , PGresult * res , int rownum );
81
83
static void ReceiveAndUnpackTarFile (PGconn * conn , PGresult * res , int rownum );
@@ -399,13 +401,27 @@ verify_dir_is_empty_or_create(char *dirname)
399
401
/*
400
402
* Print a progress report based on the global variables. If verbose output
401
403
* is enabled, also print the current file name.
404
+ *
405
+ * Progress report is written at maximum once per second, unless the
406
+ * force parameter is set to true.
402
407
*/
403
408
static void
404
- progress_report (int tablespacenum , const char * filename )
409
+ progress_report (int tablespacenum , const char * filename , bool force )
405
410
{
406
- int percent = ( int ) (( totaldone / 1024 ) * 100 / totalsize ) ;
411
+ int percent ;
407
412
char totaldone_str [32 ];
408
413
char totalsize_str [32 ];
414
+ pg_time_t now ;
415
+
416
+ if (!showprogress )
417
+ return ;
418
+
419
+ now = time (NULL );
420
+ if (now == last_progress_report && !force )
421
+ return ; /* Max once per second */
422
+
423
+ last_progress_report = now ;
424
+ percent = totalsize ? (int ) ((totaldone / 1024 ) * 100 / totalsize ) : 0 ;
409
425
410
426
/*
411
427
* Avoid overflowing past 100% or the full size. This may make the total
@@ -853,9 +869,9 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
853
869
}
854
870
}
855
871
totaldone += r ;
856
- if (showprogress )
857
- progress_report (rownum , filename );
872
+ progress_report (rownum , filename , false);
858
873
} /* while (1) */
874
+ progress_report (rownum , filename , true);
859
875
860
876
if (copybuf != NULL )
861
877
PQfreemem (copybuf );
@@ -1080,8 +1096,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
1080
1096
disconnect_and_exit (1 );
1081
1097
}
1082
1098
totaldone += r ;
1083
- if (showprogress )
1084
- progress_report (rownum , filename );
1099
+ progress_report (rownum , filename , false);
1085
1100
1086
1101
current_len_left -= r ;
1087
1102
if (current_len_left == 0 && current_padding == 0 )
@@ -1097,6 +1112,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
1097
1112
}
1098
1113
} /* continuing data in existing file */
1099
1114
} /* loop over all data blocks */
1115
+ progress_report (rownum , filename , true);
1100
1116
1101
1117
if (file != NULL )
1102
1118
{
@@ -1457,8 +1473,7 @@ BaseBackup(void)
1457
1473
tablespacecount = PQntuples (res );
1458
1474
for (i = 0 ; i < PQntuples (res ); i ++ )
1459
1475
{
1460
- if (showprogress )
1461
- totalsize += atol (PQgetvalue (res , i , 2 ));
1476
+ totalsize += atol (PQgetvalue (res , i , 2 ));
1462
1477
1463
1478
/*
1464
1479
* Verify tablespace directories are empty. Don't bother with the
@@ -1505,7 +1520,7 @@ BaseBackup(void)
1505
1520
1506
1521
if (showprogress )
1507
1522
{
1508
- progress_report (PQntuples (res ), NULL );
1523
+ progress_report (PQntuples (res ), NULL , true );
1509
1524
fprintf (stderr , "\n" ); /* Need to move to next line */
1510
1525
}
1511
1526
PQclear (res );
0 commit comments