1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-09 06:21:09 +03:00

pg_basebackup pg_receivexlog: Issue fsync more carefully

Several places weren't careful about fsyncing in the way.  See 1d4a0ab1
and 606e0f98 for details about required fsyncs.

This adds a couple of functions in src/common/ that have an equivalent
in the backend: durable_rename(), fsync_parent_path()

From: Michael Paquier <michael.paquier@gmail.com>
This commit is contained in:
Peter Eisentraut
2016-09-29 12:00:00 -04:00
parent bf5bb2e85b
commit bc34223bc1
4 changed files with 164 additions and 31 deletions

View File

@@ -27,6 +27,7 @@
#include <zlib.h>
#endif
#include "common/file_utils.h"
#include "common/string.h"
#include "fe_utils/string_utils.h"
#include "getopt_long.h"
@@ -1196,6 +1197,10 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
if (copybuf != NULL)
PQfreemem(copybuf);
/* sync the resulting tar file, errors are not considered fatal */
if (strcmp(basedir, "-") != 0)
(void) fsync_fname(filename, false, progname);
}
@@ -1472,6 +1477,11 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
if (basetablespace && writerecoveryconf)
WriteRecoveryConf();
/*
* No data is synced here, everything is done for all tablespaces at the
* end.
*/
}
/*
@@ -1950,6 +1960,23 @@ BaseBackup(void)
PQclear(res);
PQfinish(conn);
/*
* Make data persistent on disk once backup is completed. For tar
* format once syncing the parent directory is fine, each tar file
* created per tablespace has been already synced. In plain format,
* all the data of the base directory is synced, taking into account
* all the tablespaces. Errors are not considered fatal.
*/
if (format == 't')
{
if (strcmp(basedir, "-") != 0)
(void) fsync_fname(basedir, true, progname);
}
else
{
(void) fsync_pgdata(basedir, progname);
}
if (verbose)
fprintf(stderr, "%s: base backup completed\n", progname);
}