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

Commit996c92b

Browse files
committed
Delay fsyncs of pg_basebackup until the end of backup
Since the addition of fsync requests in bc34223 to make base backup dataconsistent on disk once pg_basebackup finishes, each tablespace tar fileis individually flushed once completed, with an additional flush of theparent directory when the base backup finishes. While holding aconnection to the server, a fsync request taking a long time may cause afailure of the base backup, which is annoying for any integration. Arecent example of breakage can involve tcp_user_timeout, butwal_sender_timeout can cause similar problems.While reviewing the code, there was a second issue causing too manyfsync requests to be done for the same WAL data. As recursive fsyncsare done at the end of the backup for both the plain and tar formatsfrom the base target directory where everything is written, it is fineto disable fsyncs when fetching or streaming WAL.Reported-by: Ryohei TakahashiAuthor: Michael PaquierReviewed-by: Ryohei TakahashiDiscussion:https://postgr.es/m/OSBPR01MB4550DAE2F8C9502894A45AAB82BE0@OSBPR01MB4550.jpnprd01.prod.outlook.comBackpatch-through: 10
1 parentf967a1f commit996c92b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,18 @@ LogStreamerMain(logstreamer_param *param)
501501
#endif
502502
stream.standby_message_timeout=standby_message_timeout;
503503
stream.synchronous= false;
504-
stream.do_sync=do_sync;
504+
/* fsync happens at the end of pg_basebackup for all data */
505+
stream.do_sync= false;
505506
stream.mark_done= true;
506507
stream.partial_suffix=NULL;
507508
stream.replication_slot=replication_slot;
508509

509510
if (format=='p')
510-
stream.walmethod=CreateWalDirectoryMethod(param->xlog,0,do_sync);
511+
stream.walmethod=CreateWalDirectoryMethod(param->xlog,0,
512+
stream.do_sync);
511513
else
512-
stream.walmethod=CreateWalTarMethod(param->xlog,compresslevel,do_sync);
514+
stream.walmethod=CreateWalTarMethod(param->xlog,compresslevel,
515+
stream.do_sync);
513516

514517
if (!ReceiveXlogStream(param->bgconn,&stream))
515518

@@ -1303,9 +1306,10 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
13031306
if (copybuf!=NULL)
13041307
PQfreemem(copybuf);
13051308

1306-
/* sync the resulting tar file, errors are not considered fatal */
1307-
if (do_sync&&strcmp(basedir,"-")!=0)
1308-
(void)fsync_fname(filename, false,progname);
1309+
/*
1310+
* Do not sync the resulting tar file yet, all files are synced once at
1311+
* the end.
1312+
*/
13091313
}
13101314

13111315

@@ -2105,17 +2109,17 @@ BaseBackup(void)
21052109

21062110
/*
21072111
* Make data persistent on disk once backup is completed. For tar format
2108-
*once syncingthe parent directoryis fine,each tar filecreated per
2109-
*tablespace has been already synced.In plain format, all the data of
2110-
*thebase directory is synced, taking into account all the tablespaces.
2112+
*syncthe parent directoryand all its contents aseach tar filewas not
2113+
*synced after being completed.In plain format, all the data of the
2114+
* base directory is synced, taking into account all the tablespaces.
21112115
* Errors are not considered fatal.
21122116
*/
21132117
if (do_sync)
21142118
{
21152119
if (format=='t')
21162120
{
21172121
if (strcmp(basedir,"-")!=0)
2118-
(void)fsync_fname(basedir, true,progname);
2122+
(void)fsync_dir_recurse(basedir,progname);
21192123
}
21202124
else
21212125
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp