aboutsummaryrefslogtreecommitdiff
path: root/src/common/file_utils.c
diff options
context:
space:
mode:
authorNathan Bossart <nathan@postgresql.org>2025-03-25 16:02:35 -0500
committerNathan Bossart <nathan@postgresql.org>2025-03-25 16:02:35 -0500
commit626d7236b65da50423df7de035e86f273cd36b49 (patch)
treecaa5496310260ed60cb6da76c84f042a2802ae27 /src/common/file_utils.c
parent9c49f0e8cd7d59e240f5da88decf2d62d8a4ad0d (diff)
downloadpostgresql-626d7236b65da50423df7de035e86f273cd36b49.tar.gz
postgresql-626d7236b65da50423df7de035e86f273cd36b49.zip
pg_upgrade: Add --swap for faster file transfer.
This new option instructs pg_upgrade to move the data directories from the old cluster to the new cluster and then to replace the catalog files with those generated for the new cluster. This mode can outperform --link, --clone, --copy, and --copy-file-range, especially on clusters with many relations. However, this mode creates many garbage files in the old cluster, which can prolong the file synchronization step if --sync-method=syncfs is used. To handle that, we recommend using --sync-method=fsync with this mode, and pg_upgrade internally uses "initdb --sync-only --no-sync-data-files" for file synchronization. pg_upgrade will synchronize the catalog files as they are transferred. We assume that the database files transferred from the old cluster were synchronized prior to upgrade. This mode also complicates reverting to the old cluster, so we recommend restoring from backup upon failure during or after file transfer. We did consider teaching pg_upgrade how to generate a revert script for such failures, but we decided against it due to the rarity of failing during file transfer, the complexity of generating the script, and the potential for misusing the script. The new mode is limited to clusters located in the same file system. With some effort, we could probably support upgrades between different file systems, but this mode is unlikely to offer much benefit if we have to copy the files across file system boundaries. It is also limited to upgrades from version 10 or newer. There are a few known obstacles for using swap mode to upgrade from older versions. For example, the visibility map format changed in v9.6, and the sequence tuple format changed in v10. In fact, swap mode omits the --sequence-data option in its uses of pg_dump and instead reuses the old cluster's sequence data files. While teaching swap mode to deal with these kinds of changes is surely possible (and we may have to deal with similar problems in the future, anyway), it doesn't seem worth the effort to support upgrades from long-unsupported versions. Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://postgr.es/m/Zyvop-LxLXBLrZil%40nathan
Diffstat (limited to 'src/common/file_utils.c')
-rw-r--r--src/common/file_utils.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/common/file_utils.c b/src/common/file_utils.c
index 1e6250cc190..7b62687a2aa 100644
--- a/src/common/file_utils.c
+++ b/src/common/file_utils.c
@@ -45,9 +45,6 @@
*/
#define MINIMUM_VERSION_FOR_PG_WAL 100000
-#ifdef PG_FLUSH_DATA_WORKS
-static int pre_sync_fname(const char *fname, bool isdir);
-#endif
static void walkdir(const char *path,
int (*action) (const char *fname, bool isdir),
bool process_symlinks,
@@ -352,16 +349,16 @@ walkdir(const char *path,
}
/*
- * Hint to the OS that it should get ready to fsync() this file.
+ * Hint to the OS that it should get ready to fsync() this file, if supported
+ * by the platform.
*
* Ignores errors trying to open unreadable files, and reports other errors
* non-fatally.
*/
-#ifdef PG_FLUSH_DATA_WORKS
-
-static int
+int
pre_sync_fname(const char *fname, bool isdir)
{
+#ifdef PG_FLUSH_DATA_WORKS
int fd;
fd = open(fname, O_RDONLY | PG_BINARY, 0);
@@ -388,11 +385,10 @@ pre_sync_fname(const char *fname, bool isdir)
#endif
(void) close(fd);
+#endif /* PG_FLUSH_DATA_WORKS */
return 0;
}
-#endif /* PG_FLUSH_DATA_WORKS */
-
/*
* fsync_fname -- Try to fsync a file or directory
*