diff options
author | Thomas Munro <tmunro@postgresql.org> | 2025-04-08 20:52:47 +1200 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2025-04-08 21:35:38 +1200 |
commit | f78ca6f3ebbbff8c675c34b8ee61047223073866 (patch) | |
tree | c3543200c7b119226fb6b1266db6dfd463b02267 /src/backend/utils/misc/guc_tables.c | |
parent | 042a66291b04f473cbc72f95f07438abd75ae3a9 (diff) | |
download | postgresql-f78ca6f3ebbbff8c675c34b8ee61047223073866.tar.gz postgresql-f78ca6f3ebbbff8c675c34b8ee61047223073866.zip |
Introduce file_copy_method setting.
It can be set to either COPY (the default) or CLONE if the system
supports it. CLONE causes callers of copydir(), currently CREATE
DATABASE ... STRATEGY=FILE_COPY and ALTER DATABASE ... SET TABLESPACE =
..., to use copy_file_range (Linux, FreeBSD) or copyfile (macOS) to copy
files instead of a read-write loop over the contents.
CLONE gives the kernel the opportunity to share block ranges on
copy-on-write file systems and push copying down to storage on others,
depending on configuration. On some systems CLONE can be used to clone
large databases quickly with CREATE DATABASE ... TEMPLATE=source
STRATEGY=FILE_COPY.
Other operating systems could be supported; patches welcome.
Co-authored-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Discussion: https://postgr.es/m/CA%2BhUKGLM%2Bt%2BSwBU-cHeMUXJCOgBxSHLGZutV5zCwY4qrCcE02w%40mail.gmail.com
Diffstat (limited to 'src/backend/utils/misc/guc_tables.c')
-rw-r--r-- | src/backend/utils/misc/guc_tables.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index d54df555fba..60b12446a1c 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -20,6 +20,9 @@ */ #include "postgres.h" +#ifdef HAVE_COPYFILE_H +#include <copyfile.h> +#endif #include <float.h> #include <limits.h> #ifdef HAVE_SYSLOG @@ -76,6 +79,7 @@ #include "storage/aio.h" #include "storage/bufmgr.h" #include "storage/bufpage.h" +#include "storage/copydir.h" #include "storage/io_worker.h" #include "storage/large_object.h" #include "storage/pg_shmem.h" @@ -479,6 +483,14 @@ static const struct config_enum_entry wal_compression_options[] = { {NULL, 0, false} }; +static const struct config_enum_entry file_copy_method_options[] = { + {"copy", FILE_COPY_METHOD_COPY, false}, +#if defined(HAVE_COPYFILE) && defined(COPYFILE_CLONE_FORCE) || defined(HAVE_COPY_FILE_RANGE) + {"clone", FILE_COPY_METHOD_CLONE, false}, +#endif + {NULL, 0, false} +}; + /* * Options for enum values stored in other modules */ @@ -5243,6 +5255,16 @@ struct config_enum ConfigureNamesEnum[] = }, { + {"file_copy_method", PGC_USERSET, RESOURCES_DISK, + gettext_noop("Selects the file copy method."), + NULL + }, + &file_copy_method, + FILE_COPY_METHOD_COPY, file_copy_method_options, + NULL, NULL, NULL + }, + + { {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS, gettext_noop("Selects the method used for forcing WAL updates to disk."), NULL |