1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-19 13:42:17 +03:00

Allow using syncfs() in frontend utilities.

This commit allows specifying a --sync-method in several frontend
utilities that must synchronize many files to disk (initdb,
pg_basebackup, pg_checksums, pg_dump, pg_rewind, and pg_upgrade).
On Linux, users can specify "syncfs" to synchronize the relevant
file systems instead of calling fsync() for every single file.  In
many cases, using syncfs() is much faster.

As with recovery_init_sync_method, this new option comes with some
caveats.  The descriptions of these caveats have been moved to a
new appendix section in the documentation.

Co-authored-by: Justin Pryzby
Reviewed-by: Michael Paquier, Thomas Munro, Robert Haas, Justin Pryzby
Discussion: https://postgr.es/m/20210930004340.GM831%40telsasoft.com
This commit is contained in:
Nathan Bossart
2023-09-06 16:27:16 -07:00
parent cccc6cdeb3
commit 8c16ad3b43
21 changed files with 271 additions and 11 deletions

View File

@@ -82,3 +82,30 @@ option_parse_int(const char *optarg, const char *optname,
*result = val;
return true;
}
/*
* Provide strictly harmonized handling of the --sync-method option.
*/
bool
parse_sync_method(const char *optarg, DataDirSyncMethod *sync_method)
{
if (strcmp(optarg, "fsync") == 0)
*sync_method = DATA_DIR_SYNC_METHOD_FSYNC;
else if (strcmp(optarg, "syncfs") == 0)
{
#ifdef HAVE_SYNCFS
*sync_method = DATA_DIR_SYNC_METHOD_SYNCFS;
#else
pg_log_error("this build does not support sync method \"%s\"",
"syncfs");
return false;
#endif
}
else
{
pg_log_error("unrecognized sync method: %s", optarg);
return false;
}
return true;
}