Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8198a32

Browse files
committed
Limit pg_basebackup progress output to 1/second
This prevents pg_basebackup from generating excessive output whendumping large clusters. The status is now updated once / second,still making it possible to see that there is progress happening,but limiting the total bandwidth.Mika Eloranta, reviewed by Sawada Masahiko and Oskari Saarenmaa
1 parent01025d8 commit8198a32

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include"libpq-fe.h"
1616
#include"pqexpbuffer.h"
1717
#include"pgtar.h"
18+
#include"pgtime.h"
1819

1920
#include<unistd.h>
2021
#include<dirent.h>
@@ -46,6 +47,7 @@ static boolstreamwal = false;
4647
staticboolfastcheckpoint= false;
4748
staticboolwriterecoveryconf= false;
4849
staticintstandby_message_timeout=10*1000;/* 10 sec = default */
50+
staticpg_time_tlast_progress_report=0;
4951

5052
/* Progress counters */
5153
staticuint64totalsize;
@@ -75,7 +77,7 @@ static PQExpBuffer recoveryconfcontents = NULL;
7577
/* Function headers */
7678
staticvoidusage(void);
7779
staticvoidverify_dir_is_empty_or_create(char*dirname);
78-
staticvoidprogress_report(inttablespacenum,constchar*filename);
80+
staticvoidprogress_report(inttablespacenum,constchar*filename,boolforce);
7981

8082
staticvoidReceiveTarFile(PGconn*conn,PGresult*res,intrownum);
8183
staticvoidReceiveAndUnpackTarFile(PGconn*conn,PGresult*res,intrownum);
@@ -399,13 +401,27 @@ verify_dir_is_empty_or_create(char *dirname)
399401
/*
400402
* Print a progress report based on the global variables. If verbose output
401403
* 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.
402407
*/
403408
staticvoid
404-
progress_report(inttablespacenum,constchar*filename)
409+
progress_report(inttablespacenum,constchar*filename,boolforce)
405410
{
406-
intpercent= (int) ((totaldone /1024)*100 /totalsize);
411+
intpercent;
407412
chartotaldone_str[32];
408413
chartotalsize_str[32];
414+
pg_time_tnow;
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;
409425

410426
/*
411427
* Avoid overflowing past 100% or the full size. This may make the total
@@ -853,9 +869,9 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
853869
}
854870
}
855871
totaldone+=r;
856-
if (showprogress)
857-
progress_report(rownum,filename);
872+
progress_report(rownum,filename, false);
858873
}/* while (1) */
874+
progress_report(rownum,filename, true);
859875

860876
if (copybuf!=NULL)
861877
PQfreemem(copybuf);
@@ -1080,8 +1096,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
10801096
disconnect_and_exit(1);
10811097
}
10821098
totaldone+=r;
1083-
if (showprogress)
1084-
progress_report(rownum,filename);
1099+
progress_report(rownum,filename, false);
10851100

10861101
current_len_left-=r;
10871102
if (current_len_left==0&&current_padding==0)
@@ -1097,6 +1112,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
10971112
}
10981113
}/* continuing data in existing file */
10991114
}/* loop over all data blocks */
1115+
progress_report(rownum,filename, true);
11001116

11011117
if (file!=NULL)
11021118
{
@@ -1457,8 +1473,7 @@ BaseBackup(void)
14571473
tablespacecount=PQntuples(res);
14581474
for (i=0;i<PQntuples(res);i++)
14591475
{
1460-
if (showprogress)
1461-
totalsize+=atol(PQgetvalue(res,i,2));
1476+
totalsize+=atol(PQgetvalue(res,i,2));
14621477

14631478
/*
14641479
* Verify tablespace directories are empty. Don't bother with the
@@ -1505,7 +1520,7 @@ BaseBackup(void)
15051520

15061521
if (showprogress)
15071522
{
1508-
progress_report(PQntuples(res),NULL);
1523+
progress_report(PQntuples(res),NULL, true);
15091524
fprintf(stderr,"\n");/* Need to move to next line */
15101525
}
15111526
PQclear(res);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp