mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-22 14:27:00 +08:00
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
67 lines
1.8 KiB
C
67 lines
1.8 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* Assorted utility functions to work on files.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/common/file_utils.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef FILE_UTILS_H
|
|
#define FILE_UTILS_H
|
|
|
|
#include <dirent.h>
|
|
|
|
typedef enum PGFileType
|
|
{
|
|
PGFILETYPE_ERROR,
|
|
PGFILETYPE_UNKNOWN,
|
|
PGFILETYPE_REG,
|
|
PGFILETYPE_DIR,
|
|
PGFILETYPE_LNK,
|
|
} PGFileType;
|
|
|
|
typedef enum DataDirSyncMethod
|
|
{
|
|
DATA_DIR_SYNC_METHOD_FSYNC,
|
|
DATA_DIR_SYNC_METHOD_SYNCFS,
|
|
} DataDirSyncMethod;
|
|
|
|
struct iovec; /* avoid including port/pg_iovec.h here */
|
|
|
|
#ifdef FRONTEND
|
|
extern int pre_sync_fname(const char *fname, bool isdir);
|
|
extern int fsync_fname(const char *fname, bool isdir);
|
|
extern void sync_pgdata(const char *pg_data, int serverVersion,
|
|
DataDirSyncMethod sync_method, bool sync_data_files);
|
|
extern void sync_dir_recurse(const char *dir, DataDirSyncMethod sync_method);
|
|
extern int durable_rename(const char *oldfile, const char *newfile);
|
|
extern int fsync_parent_path(const char *fname);
|
|
#endif
|
|
|
|
extern PGFileType get_dirent_type(const char *path,
|
|
const struct dirent *de,
|
|
bool look_through_symlinks,
|
|
int elevel);
|
|
|
|
extern int compute_remaining_iovec(struct iovec *destination,
|
|
const struct iovec *source,
|
|
int iovcnt,
|
|
size_t transferred);
|
|
|
|
extern ssize_t pg_pwritev_with_retry(int fd,
|
|
const struct iovec *iov,
|
|
int iovcnt,
|
|
off_t offset);
|
|
|
|
extern ssize_t pg_pwrite_zeros(int fd, size_t size, off_t offset);
|
|
|
|
/* Filename components */
|
|
#define PG_TEMP_FILES_DIR "pgsql_tmp"
|
|
#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
|
|
|
|
#endif /* FILE_UTILS_H */
|