{"Entry":{"collection":"tool","key":"pg-upgrade","name":"pg_upgrade","aliases":["pg_upgrade"],"metadata":{"aliases":["pg_upgrade"],"category":"Server applications","content_hash":"89f68069179a1e9cd06bc2e7e7d25ca07adec5f774222b29013e3e10e1a2b2ad","imported_at":"2026-09-30T00:40:34.451557+08:00","name":"pg_upgrade","name_zh":"","slug":"pg-upgrade","summary":"pg_upgrade — upgrade a PostgreSQL server instance"}},"Definition":{"Collection":"tool","Key":"pg-upgrade","SourceDatabase":"center","Version":"18","SourceTable":"command_tool","SourceKey":"pg-upgrade","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","Facts":{"comparison_data":{"environment":[{"description":"The old PostgreSQL executable directory; option -b / --old-bindir .","name":"PGBINOLD"},{"description":"The new PostgreSQL executable directory; option -B / --new-bindir .","name":"PGBINNEW"},{"description":"The old database cluster configuration directory; option -d / --old-datadir .","name":"PGDATAOLD"},{"description":"The new database cluster configuration directory; option -D / --new-datadir .","name":"PGDATANEW"},{"description":"The old cluster port number; option -p / --old-port .","name":"PGPORTOLD"},{"description":"The new cluster port number; option -P / --new-port .","name":"PGPORTNEW"},{"description":"Directory to use for postmaster sockets during upgrade; option -s / --socketdir .","name":"PGSOCKETDIR"},{"description":"Cluster's install user name; option -U / --username .","name":"PGUSER"}],"options":[{"description":"the old PostgreSQL executable directory; environment variable PGBINOLD","names":["-b","--old-bindir="],"signature":"-b bindir --old-bindir= bindir"},{"description":"the new PostgreSQL executable directory; default is the directory where pg_upgrade resides; environment variable PGBINNEW","names":["-B","--new-bindir="],"signature":"-B bindir --new-bindir= bindir"},{"description":"check clusters only, don't change any data","names":["-c","--check"],"signature":"-c --check"},{"description":"the old database cluster configuration directory; environment variable PGDATAOLD","names":["-d","--old-datadir="],"signature":"-d configdir --old-datadir= configdir"},{"description":"the new database cluster configuration directory; environment variable PGDATANEW","names":["-D","--new-datadir="],"signature":"-D configdir --new-datadir= configdir"},{"description":"number of simultaneous connections and processes/threads to use","names":["-j njobs","--jobs= njobs"],"signature":"-j njobs --jobs= njobs"},{"description":"use hard links instead of copying files to the new cluster","names":["-k","--link"],"signature":"-k --link"},{"description":"By default, pg_upgrade will wait for all files of the upgraded cluster to be written safely to disk. This option causes pg_upgrade to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation.","names":["-N","--no-sync"],"signature":"-N --no-sync"},{"description":"options to be passed directly to the old postgres command; multiple option invocations are appended","names":["-o","--old-options"],"signature":"-o options --old-options options"},{"description":"options to be passed directly to the new postgres command; multiple option invocations are appended","names":["-O","--new-options"],"signature":"-O options --new-options options"},{"description":"the old cluster port number; environment variable PGPORTOLD","names":["-p","--old-port="],"signature":"-p port --old-port= port"},{"description":"the new cluster port number; environment variable PGPORTNEW","names":["-P","--new-port="],"signature":"-P port --new-port= port"},{"description":"retain SQL and log files even after successful completion","names":["-r","--retain"],"signature":"-r --retain"},{"description":"directory to use for postmaster sockets during upgrade; default is current working directory; environment variable PGSOCKETDIR","names":["-s","--socketdir="],"signature":"-s dir --socketdir= dir"},{"description":"cluster's install user name; environment variable PGUSER","names":["-U","--username="],"signature":"-U username --username= username"},{"description":"enable verbose internal logging","names":["-v","--verbose"],"signature":"-v --verbose"},{"description":"display version information, then exit","names":["-V","--version"],"signature":"-V --version"},{"description":"Use efficient file cloning (also known as “ reflinks ” on some systems) instead of copying files to the new cluster. This can result in near-instantaneous copying of the data files, giving the speed advantages of -k / --link while leaving the old cluster untouched. File cloning is only supported on some operating systems and file systems. If it is selected but not supported, the pg_upgrade run will error. At present, it is supported on Linux (kernel 4.5 or later) with Btrfs and XFS (on file systems created with reflink support), and on macOS with APFS.","names":["--clone"],"signature":"--clone"},{"description":"Copy files to the new cluster. This is the default. (See also --link , --clone , --copy-file-range , and --swap .)","names":["--copy"],"signature":"--copy"},{"description":"Use the copy_file_range system call for efficient copying. On some file systems this gives results similar to --clone , sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path. At present, it is supported on Linux and FreeBSD.","names":["--copy-file-range"],"signature":"--copy-file-range"},{"description":"Do not restore statistics from the old cluster into the new cluster.","names":["--no-statistics"],"signature":"--no-statistics"},{"description":"Manually set the default char signedness of new clusters. Possible values are signed and unsigned . In the C language, the default signedness of the char type (when not explicitly specified) varies across platforms. For example, char defaults to signed char on x86 CPUs but to unsigned char on ARM CPUs. Starting from PostgreSQL 18, database clusters maintain their own default char signedness setting, which can be used to ensure consistent behavior across platforms with different default char signedness. By default, pg_upgrade preserves the char signedness setting when upgrading from an existing cluster. However, when upgrading from PostgreSQL 17 or earlier, pg_upgrade adopts the char signedness of the platform on which it was built. This option allows you to explicitly set the default char signedness for the new cluster, overriding any inherited values. There are two specific scenarios where this option is relevant: If you are planning to migrate to a different platform after the upgrade, you should not use this option. The default behavior is right in this case. Instead, perform the upgrade on the original platform without this flag, and then migrate the cluster afterward. This is the recommended and safest approach. If you have already migrated the cluster to a platform with different char signedness (for example, from an x86-based system to an ARM-based system), you should use this option to specify the signedness matching the original platform's default char signedness. Additionally, it's essential not to modify any data files between migrating data files and running pg_upgrade . pg_upgrade should be the first operation that starts the cluster on the new platform.","names":["--set-char-signedness="],"signature":"--set-char-signedness= option"},{"description":"Move the data directories from the old cluster to the new cluster. Then, 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. Therefore, it is recommended to use --sync-method=fsync with --swap . Additionally, once the file transfer step begins, the old cluster will be destructively modified and therefore will no longer be safe to start. See Step 17 for details.","names":["--swap"],"signature":"--swap"},{"description":"When set to fsync , which is the default, pg_upgrade will recursively open and synchronize all files in the upgraded cluster's data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file systems that contain the upgraded cluster's data directory, its WAL files, and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used.","names":["--sync-method="],"signature":"--sync-method= method"},{"description":"show help, then exit","names":["-?","--help"],"signature":"-? --help"}],"synopsis":["pg_upgrade -b oldbindir [ -B newbindir ] -d oldconfigdir -D newconfigdir [ option ...]"]},"comparison_hash":"ed8c09156ba62bb3138b603b905750e0ebd88baadd61089e3fe1a1e8186934e5","description":["pg_upgrade — upgrade a PostgreSQL server instance"],"environment":[{"description":"The old PostgreSQL executable directory; option -b / --old-bindir .","name":"PGBINOLD"},{"description":"The new PostgreSQL executable directory; option -B / --new-bindir .","name":"PGBINNEW"},{"description":"The old database cluster configuration directory; option -d / --old-datadir .","name":"PGDATAOLD"},{"description":"The new database cluster configuration directory; option -D / --new-datadir .","name":"PGDATANEW"},{"description":"The old cluster port number; option -p / --old-port .","name":"PGPORTOLD"},{"description":"The new cluster port number; option -P / --new-port .","name":"PGPORTNEW"},{"description":"Directory to use for postmaster sockets during upgrade; option -s / --socketdir .","name":"PGSOCKETDIR"},{"description":"Cluster's install user name; option -U / --username .","name":"PGUSER"}],"facts":[{"label":"Documented executable","value":"pg_upgrade"},{"label":"Executable version","value":"18.6"},{"label":"Reference inventory","value":"Server applications"},{"label":"Option definition groups","value":"25"}],"manual_html":"\u003cdiv\u003e\u003cdiv class=\"refentry\" id=\"PGUPGRADE\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\u003c/div\u003e\n\u003cdiv class=\"refnamediv\"\u003e\n\u003ch2\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_upgrade — upgrade a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server instance\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsynopsisdiv\"\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv class=\"cmdsynopsis\"\u003e\n\u003cp id=\"id-1.9.5.13.4.1\"\u003e\u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e \u003ccode class=\"option\"\u003e-b\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldbindir\u003c/code\u003e\u003c/em\u003e [\u003ccode class=\"option\"\u003e-B\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003enewbindir\u003c/code\u003e\u003c/em\u003e] \u003ccode class=\"option\"\u003e-d\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldconfigdir\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"option\"\u003e-D\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003enewconfigdir\u003c/code\u003e\u003c/em\u003e [\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...]\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e (formerly called \u003cspan class=\"application\"\u003epg_migrator\u003c/span\u003e) allows data stored in \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e data files to be upgraded to a later \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e major version without the data dump/restore typically required for major version upgrades, e.g., from 12.14 to 13.10 or from 14.9 to 15.5. It is not required for minor version upgrades, e.g., from 12.7 to 12.8 or from 14.1 to 14.5.\u003c/p\u003e\n\u003cp\u003eMajor PostgreSQL releases regularly add new features that often change the layout of the system tables, but the internal data storage format rarely changes. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e uses this fact to perform rapid upgrades by creating new system tables and simply reusing the old user data files. If a future major release ever changes the data storage format in a way that makes the old data format unreadable, \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e will not be usable for such upgrades. (The community will attempt to avoid such situations.)\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e does its best to make sure the old and new clusters are binary-compatible, e.g., by checking for compatible compile-time settings, including 32/64-bit binaries. It is important that any external modules are also binary compatible, though this cannot be checked by \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e supports upgrades from 9.2.X and later to the current major release of \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e, including snapshot and beta releases.\u003c/p\u003e\n\u003cdiv class=\"warning\"\u003e\n\u003ch3 class=\"title\"\u003eWarning\u003c/h3\u003e\n\u003cp\u003eUpgrading a cluster causes the destination to execute arbitrary code of the source superusers' choice. Ensure that the source superusers are trusted before upgrading.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-b\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--old-bindir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old PostgreSQL executable directory; environment variable \u003ccode class=\"envar\"\u003ePGBINOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-B\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--new-bindir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new PostgreSQL executable directory; default is the directory where \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e resides; environment variable \u003ccode class=\"envar\"\u003ePGBINNEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-c\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--check\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003echeck clusters only, don't change any data\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-d\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--old-datadir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old database cluster configuration directory; environment variable \u003ccode class=\"envar\"\u003ePGDATAOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-D\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--new-datadir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new database cluster configuration directory; environment variable \u003ccode class=\"envar\"\u003ePGDATANEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-j \u003cem class=\"replaceable\"\u003e\u003ccode\u003enjobs\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--jobs=\u003cem class=\"replaceable\"\u003e\u003ccode\u003enjobs\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003enumber of simultaneous connections and processes/threads to use\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-k\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--link\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003euse hard links instead of copying files to the new cluster\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-N\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--no-sync\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eBy default, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will wait for all files of the upgraded cluster to be written safely to disk. This option causes \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-o\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--old-options\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eoptions to be passed directly to the old \u003ccode class=\"command\"\u003epostgres\u003c/code\u003e command; multiple option invocations are appended\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-O\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--new-options\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eoptions to be passed directly to the new \u003ccode class=\"command\"\u003epostgres\u003c/code\u003e command; multiple option invocations are appended\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-p\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--old-port=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old cluster port number; environment variable \u003ccode class=\"envar\"\u003ePGPORTOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-P\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--new-port=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new cluster port number; environment variable \u003ccode class=\"envar\"\u003ePGPORTNEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-r\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--retain\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eretain SQL and log files even after successful completion\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-s\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--socketdir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003edirectory to use for postmaster sockets during upgrade; default is current working directory; environment variable \u003ccode class=\"envar\"\u003ePGSOCKETDIR\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-U\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--username=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ecluster's install user name; environment variable \u003ccode class=\"envar\"\u003ePGUSER\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-v\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--verbose\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eenable verbose internal logging\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003edisplay version information, then exit\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--clone\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse efficient file cloning (also known as \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003ereflinks\u003c/span\u003e”\u003c/span\u003e on some systems) instead of copying files to the new cluster. This can result in near-instantaneous copying of the data files, giving the speed advantages of \u003ccode class=\"option\"\u003e-k\u003c/code\u003e/\u003ccode class=\"option\"\u003e--link\u003c/code\u003e while leaving the old cluster untouched.\u003c/p\u003e\n\u003cp\u003eFile cloning is only supported on some operating systems and file systems. If it is selected but not supported, the \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e run will error. At present, it is supported on Linux (kernel 4.5 or later) with Btrfs and XFS (on file systems created with reflink support), and on macOS with APFS.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--copy\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCopy files to the new cluster. This is the default. (See also \u003ccode class=\"option\"\u003e--link\u003c/code\u003e, \u003ccode class=\"option\"\u003e--clone\u003c/code\u003e, \u003ccode class=\"option\"\u003e--copy-file-range\u003c/code\u003e, and \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e.)\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--copy-file-range\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse the \u003ccode class=\"function\"\u003ecopy_file_range\u003c/code\u003e system call for efficient copying. On some file systems this gives results similar to \u003ccode class=\"option\"\u003e--clone\u003c/code\u003e, sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path. At present, it is supported on Linux and FreeBSD.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--no-statistics\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDo not restore statistics from the old cluster into the new cluster.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--set-char-signedness=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eManually set the default char signedness of new clusters. Possible values are \u003ccode class=\"literal\"\u003esigned\u003c/code\u003e and \u003ccode class=\"literal\"\u003eunsigned\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eIn the C language, the default signedness of the \u003ccode class=\"type\"\u003echar\u003c/code\u003e type (when not explicitly specified) varies across platforms. For example, \u003ccode class=\"type\"\u003echar\u003c/code\u003e defaults to \u003ccode class=\"type\"\u003esigned char\u003c/code\u003e on x86 CPUs but to \u003ccode class=\"type\"\u003eunsigned char\u003c/code\u003e on ARM CPUs.\u003c/p\u003e\n\u003cp\u003eStarting from \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 18, database clusters maintain their own default char signedness setting, which can be used to ensure consistent behavior across platforms with different default char signedness. By default, \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e preserves the char signedness setting when upgrading from an existing cluster. However, when upgrading from \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 17 or earlier, \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e adopts the char signedness of the platform on which it was built.\u003c/p\u003e\n\u003cp\u003eThis option allows you to explicitly set the default char signedness for the new cluster, overriding any inherited values. There are two specific scenarios where this option is relevant:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf you are planning to migrate to a different platform after the upgrade, you should not use this option. The default behavior is right in this case. Instead, perform the upgrade on the original platform without this flag, and then migrate the cluster afterward. This is the recommended and safest approach.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf you have already migrated the cluster to a platform with different char signedness (for example, from an x86-based system to an ARM-based system), you should use this option to specify the signedness matching the original platform's default char signedness. Additionally, it's essential not to modify any data files between migrating data files and running \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e. \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e should be the first operation that starts the cluster on the new platform.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--swap\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eMove the data directories from the old cluster to the new cluster. Then, replace the catalog files with those generated for the new cluster. This mode can outperform \u003ccode class=\"option\"\u003e--link\u003c/code\u003e, \u003ccode class=\"option\"\u003e--clone\u003c/code\u003e, \u003ccode class=\"option\"\u003e--copy\u003c/code\u003e, and \u003ccode class=\"option\"\u003e--copy-file-range\u003c/code\u003e, especially on clusters with many relations.\u003c/p\u003e\n\u003cp\u003eHowever, this mode creates many garbage files in the old cluster, which can prolong the file synchronization step if \u003ccode class=\"option\"\u003e--sync-method=syncfs\u003c/code\u003e is used. Therefore, it is recommended to use \u003ccode class=\"option\"\u003e--sync-method=fsync\u003c/code\u003e with \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eAdditionally, once the file transfer step begins, the old cluster will be destructively modified and therefore will no longer be safe to start. See \u003ca class=\"xref\" href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REVERT\" title=\"Reverting to old cluster\"\u003eStep 17\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--sync-method=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003emethod\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWhen set to \u003ccode class=\"literal\"\u003efsync\u003c/code\u003e, which is the default, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will recursively open and synchronize all files in the upgraded cluster's data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace.\u003c/p\u003e\n\u003cp\u003eOn Linux, \u003ccode class=\"literal\"\u003esyncfs\u003c/code\u003e may be used instead to ask the operating system to synchronize the whole file systems that contain the upgraded cluster's data directory, its WAL files, and each tablespace. See \u003ca class=\"xref\" href=\"/docs/18/runtime-config-error-handling.html#GUC-RECOVERY-INIT-SYNC-METHOD\"\u003erecovery_init_sync_method\u003c/a\u003e for information about the caveats to be aware of when using \u003ccode class=\"literal\"\u003esyncfs\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThis option has no effect when \u003ccode class=\"option\"\u003e--no-sync\u003c/code\u003e is used.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eshow help, then exit\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.7\"\u003e\n\u003ch2\u003eUsage\u003c/h2\u003e\n\u003cp\u003eThese are the steps to perform an upgrade with \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e:\u003c/p\u003e\n\u003cdiv class=\"note\"\u003e\n\u003ch3 class=\"title\"\u003eNote\u003c/h3\u003e\n\u003cp\u003eThe steps to upgrade \u003ca class=\"glossterm\" href=\"/docs/18/glossary.html#GLOSSARY-LOGICAL-REPLICATION-CLUSTER\"\u003e\u003c/a\u003e\u003ca class=\"glossterm\" href=\"/docs/18/glossary.html#GLOSSARY-LOGICAL-REPLICATION-CLUSTER\" title=\"Logical replication cluster\"\u003elogical replication clusters\u003c/a\u003e are not covered here; refer to \u003ca class=\"xref\" href=\"/docs/18/logical-replication-upgrade.html\" title=\"29.13. Upgrade\"\u003eSection 29.13\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"procedure\"\u003e\n\u003col class=\"procedure\"\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eOptionally move the old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you are using a version-specific installation directory, e.g., \u003ccode class=\"filename\"\u003e/opt/PostgreSQL/18\u003c/code\u003e, you do not need to move the old cluster. The graphical installers all use version-specific installation directories.\u003c/p\u003e\n\u003cp\u003eIf your installation directory is not version-specific, e.g., \u003ccode class=\"filename\"\u003e/usr/local/pgsql\u003c/code\u003e, it is necessary to move the current PostgreSQL install directory so it does not interfere with the new \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e installation. Once the current \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server is shut down, it is safe to rename the PostgreSQL installation directory; assuming the old directory is \u003ccode class=\"filename\"\u003e/usr/local/pgsql\u003c/code\u003e, you can do:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003emv /usr/local/pgsql /usr/local/pgsql.old\n\u003c/pre\u003e\n\u003cp\u003eto rename the directory.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eFor source installs, build the new version\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eBuild the new PostgreSQL source with \u003ccode class=\"command\"\u003econfigure\u003c/code\u003e flags that are compatible with the old cluster. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e will check \u003ccode class=\"command\"\u003epg_controldata\u003c/code\u003e to make sure all settings are compatible before starting the upgrade.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInstall the new PostgreSQL binaries\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInstall the new server's binaries and support files. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e is included in a default installation.\u003c/p\u003e\n\u003cp\u003eFor source installs, if you wish to install the new server in a custom location, use the \u003ccode class=\"literal\"\u003eprefix\u003c/code\u003e variable:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003emake prefix=/usr/local/pgsql.new install\n\u003c/pre\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInitialize the new PostgreSQL cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInitialize the new cluster using \u003ccode class=\"command\"\u003einitdb\u003c/code\u003e. Again, use compatible \u003ccode class=\"command\"\u003einitdb\u003c/code\u003e flags that match the old cluster. Many prebuilt installers do this step automatically. There is no need to start the new cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInstall extension shared object files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMany extensions and custom modules, whether from \u003ccode class=\"filename\"\u003econtrib\u003c/code\u003e or another source, use shared object files (or DLLs), e.g., \u003ccode class=\"filename\"\u003epgcrypto.so\u003c/code\u003e. If the old cluster used these, shared object files matching the new server binary must be installed in the new cluster, usually via operating system commands. Do not load the schema definitions, e.g., \u003ccode class=\"command\"\u003eCREATE EXTENSION pgcrypto\u003c/code\u003e, because these will be duplicated from the old cluster. If extension updates are available, \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e will report this and create a script that can be run later to update them.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eCopy custom full-text search files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eCopy any custom full text search files (dictionary, synonym, thesaurus, stop words) from the old to the new cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eAdjust authentication\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will connect to the old and new servers several times, so you might want to set authentication to \u003ccode class=\"literal\"\u003epeer\u003c/code\u003e in \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e or use a \u003ccode class=\"filename\"\u003e~/.pgpass\u003c/code\u003e file (see \u003ca class=\"xref\" href=\"/docs/18/libpq-pgpass.html\" title=\"32.16. The Password File\"\u003eSection 32.16\u003c/a\u003e).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eStop both servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure both database servers are stopped using, on Unix, e.g.:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epg_ctl -D /opt/PostgreSQL/12 stop\npg_ctl -D /opt/PostgreSQL/18 stop\n\u003c/pre\u003e\n\u003cp\u003eor on Windows, using the proper service names:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eNET STOP postgresql-12\nNET STOP postgresql-18\n\u003c/pre\u003e\n\u003cp\u003eStreaming replication and log-shipping standby servers must be running during this shutdown so they receive all changes.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003ePrepare for standby server upgrades\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you are upgrading standby servers using methods outlined in section \u003ca class=\"xref\" href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REPLICAS\" title=\"Upgrade streaming replication and log-shipping standby servers\"\u003eStep 11\u003c/a\u003e, verify that the old standby servers are caught up by running \u003cspan class=\"application\"\u003epg_controldata\u003c/span\u003e against the old primary and standby clusters. Verify that the \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eLatest checkpoint location\u003c/span\u003e”\u003c/span\u003e values match in all clusters. Also, make sure \u003ccode class=\"varname\"\u003ewal_level\u003c/code\u003e is not set to \u003ccode class=\"literal\"\u003eminimal\u003c/code\u003e in the \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e file on the new primary cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eRun \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eAlways run the \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e binary of the new server, not the old one. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e requires the specification of the old and new cluster's data and executable (\u003ccode class=\"filename\"\u003ebin\u003c/code\u003e) directories. You can also specify user and port values, and whether you want the data files linked, cloned, or swapped instead of the default copy behavior.\u003c/p\u003e\n\u003cp\u003eIf you use link mode, the upgrade will be much faster (no file copying) and use less disk space, but you will not be able to access your old cluster once you start the new cluster after the upgrade. Link mode also requires that the old and new cluster data directories be in the same file system. (Tablespaces and \u003ccode class=\"filename\"\u003epg_wal\u003c/code\u003e can be on different file systems.) Clone mode provides the same speed and disk space advantages but does not cause the old cluster to be unusable once the new cluster is started. Clone mode also requires that the old and new data directories be in the same file system. This mode is only available on certain operating systems and file systems. Swap mode may be the fastest if there are many relations, but you will not be able to access your old cluster once the file transfer step begins. Swap mode also requires that the old and new cluster data directories be in the same file system.\u003c/p\u003e\n\u003cp\u003eSetting \u003ccode class=\"option\"\u003e--jobs\u003c/code\u003e to 2 or higher allows pg_upgrade to process multiple databases and tablespaces in parallel. A good starting point is the number of CPU cores on the machine. This option can substantially reduce the upgrade time for multi-database and multi-tablespace servers.\u003c/p\u003e\n\u003cp\u003eFor Windows users, you must be logged into an administrative account, and then run \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e with quoted directories, e.g.:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epg_upgrade.exe\n        --old-datadir \"C:/Program Files/PostgreSQL/12/data\"\n        --new-datadir \"C:/Program Files/PostgreSQL/18/data\"\n        --old-bindir \"C:/Program Files/PostgreSQL/12/bin\"\n        --new-bindir \"C:/Program Files/PostgreSQL/18/bin\"\n\u003c/pre\u003e\n\u003cp\u003eOnce started, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will verify the two clusters are compatible and then do the upgrade. You can use \u003ccode class=\"command\"\u003epg_upgrade --check\u003c/code\u003e to perform only the checks, even if the old server is still running. \u003ccode class=\"command\"\u003epg_upgrade --check\u003c/code\u003e will also outline any manual adjustments you will need to make after the upgrade. If you are going to be using link, clone, copy-file-range, or swap mode, you should use the option \u003ccode class=\"option\"\u003e--link\u003c/code\u003e, \u003ccode class=\"option\"\u003e--clone\u003c/code\u003e, \u003ccode class=\"option\"\u003e--copy-file-range\u003c/code\u003e, or \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e with \u003ccode class=\"option\"\u003e--check\u003c/code\u003e to enable mode-specific checks. \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e requires write permission in the current directory.\u003c/p\u003e\n\u003cp\u003eObviously, no one should be accessing the clusters during the upgrade. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e defaults to running servers on port 50432 to avoid unintended client connections. You can use the same port number for both clusters when doing an upgrade because the old and new clusters will not be running at the same time. However, when checking an old running server, the old and new port numbers must be different.\u003c/p\u003e\n\u003cp\u003eIf an error occurs while restoring the database schema, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will exit and you will have to revert to the old cluster as outlined in \u003ca class=\"xref\" href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REVERT\" title=\"Reverting to old cluster\"\u003eStep 17\u003c/a\u003e below. To try \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e again, you will need to modify the old cluster so the pg_upgrade schema restore succeeds. If the problem is a \u003ccode class=\"filename\"\u003econtrib\u003c/code\u003e module, you might need to uninstall the \u003ccode class=\"filename\"\u003econtrib\u003c/code\u003e module from the old cluster and install it in the new cluster after the upgrade, assuming the module is not being used to store user data.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\" id=\"PGUPGRADE-STEP-REPLICAS\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eUpgrade streaming replication and log-shipping standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you used link mode and have Streaming Replication (see \u003ca class=\"xref\" href=\"/docs/18/warm-standby.html#STREAMING-REPLICATION\" title=\"26.2.5. Streaming Replication\"\u003eSection 26.2.5\u003c/a\u003e) or Log-Shipping (see \u003ca class=\"xref\" href=\"/docs/18/warm-standby.html\" title=\"26.2. Log-Shipping Standby Servers\"\u003eSection 26.2\u003c/a\u003e) standby servers, you can follow these steps to quickly upgrade them. You will not be running \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e on the standby servers, but rather \u003cspan class=\"application\"\u003ersync\u003c/span\u003e on the primary. Do not start any servers yet.\u003c/p\u003e\n\u003cp\u003eIf you did \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e use link mode, do not have or do not want to use \u003cspan class=\"application\"\u003ersync\u003c/span\u003e, or want an easier solution, skip the instructions in this section and simply recreate the standby servers once \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e completes and the new primary is running.\u003c/p\u003e\n\u003cdiv class=\"procedure\"\u003e\n\u003col class=\"procedure\"\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInstall the new PostgreSQL binaries on standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure the new binaries and support files are installed on all standby servers.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eMake sure the new standby data directories do \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e exist\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure the new standby data directories do \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e exist or are empty. If \u003cspan class=\"application\"\u003einitdb\u003c/span\u003e was run, delete the standby servers' new data directories.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInstall extension shared object files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInstall the same extension shared object files on the new standbys that you installed in the new primary cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eStop standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf the standby servers are still running, stop them now using the above instructions.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eSave configuration files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eSave any configuration files from the old standbys' configuration directories you need to keep, e.g., \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e (and any files included by it), \u003ccode class=\"filename\"\u003epostgresql.auto.conf\u003c/code\u003e, \u003ccode class=\"literal\"\u003epg_hba.conf\u003c/code\u003e, because these will be overwritten or removed in the next step.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eRun \u003cspan class=\"application\"\u003ersync\u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eWhen using link mode, standby servers can be quickly upgraded using \u003cspan class=\"application\"\u003ersync\u003c/span\u003e. To accomplish this, from a directory on the primary server that is above the old and new database cluster directories, run this on the \u003cspan class=\"emphasis\"\u003e\u003cem\u003eprimary\u003c/em\u003e\u003c/span\u003e for each standby server:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive old_cluster new_cluster remote_dir\n\u003c/pre\u003e\n\u003cp\u003ewhere \u003ccode class=\"option\"\u003eold_cluster\u003c/code\u003e and \u003ccode class=\"option\"\u003enew_cluster\u003c/code\u003e are relative to the current directory on the primary, and \u003ccode class=\"option\"\u003eremote_dir\u003c/code\u003e is \u003cspan class=\"emphasis\"\u003e\u003cem\u003eabove\u003c/em\u003e\u003c/span\u003e the old and new cluster directories on the standby. The directory structure under the specified directories on the primary and standbys must match. Consult the \u003cspan class=\"application\"\u003ersync\u003c/span\u003e manual page for details on specifying the remote directory, e.g.,\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive /opt/PostgreSQL/12 \\\n      /opt/PostgreSQL/18 standby.example.com:/opt/PostgreSQL\n\u003c/pre\u003e\n\u003cp\u003eYou can verify what the command will do using \u003cspan class=\"application\"\u003ersync\u003c/span\u003e's \u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e option. While \u003cspan class=\"application\"\u003ersync\u003c/span\u003e must be run on the primary for at least one standby, it is possible to run \u003cspan class=\"application\"\u003ersync\u003c/span\u003e on an upgraded standby to upgrade other standbys, as long as the upgraded standby has not been started.\u003c/p\u003e\n\u003cp\u003eWhat this does is to record the links created by \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e's link mode that connect files in the old and new clusters on the primary server. It then finds matching files in the standby's old cluster and creates links for them in the standby's new cluster. Files that were not linked on the primary are copied from the primary to the standby. (They are usually small.) This provides rapid standby upgrades. Unfortunately, \u003cspan class=\"application\"\u003ersync\u003c/span\u003e needlessly copies files associated with temporary and unlogged tables because these files don't normally exist on standby servers.\u003c/p\u003e\n\u003cp\u003eIf you have tablespaces, you will need to run a similar \u003cspan class=\"application\"\u003ersync\u003c/span\u003e command for each tablespace directory, e.g.:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive /vol1/pg_tblsp/PG_12_201909212 \\\n      /vol1/pg_tblsp/PG_18_202307071 standby.example.com:/vol1/pg_tblsp\n\u003c/pre\u003e\n\u003cp\u003eIf you have relocated \u003ccode class=\"filename\"\u003epg_wal\u003c/code\u003e outside the data directories, \u003cspan class=\"application\"\u003ersync\u003c/span\u003e must be run on those directories too.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eConfigure streaming replication and log-shipping standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eConfigure the servers for log shipping. (You do not need to run \u003ccode class=\"function\"\u003epg_backup_start()\u003c/code\u003e and \u003ccode class=\"function\"\u003epg_backup_stop()\u003c/code\u003e or take a file system backup as the standbys are still synchronized with the primary.) If the old primary is prior to version 17.0, then no slots on the primary are copied to the new standby, so all the slots on the old standby must be recreated manually. If the old primary is version 17.0 or later, then only logical slots on the primary are copied to the new standby, but other slots on the old standby are not copied, so must be recreated manually.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eRestore \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you modified \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e, restore its original settings. It might also be necessary to adjust other configuration files in the new cluster to match the old cluster, e.g., \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e (and any files included by it), \u003ccode class=\"filename\"\u003epostgresql.auto.conf\u003c/code\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eStart the new server\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe new server can now be safely started, and then any \u003cspan class=\"application\"\u003ersync\u003c/span\u003e'ed standby servers.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003ePost-upgrade processing\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf any post-upgrade processing is required, pg_upgrade will issue warnings as it completes. It will also generate script files that must be run by the administrator. The script files will connect to each database that needs post-upgrade processing. Each script should be run using:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epsql --username=postgres --file=script.sql postgres\n\u003c/pre\u003e\n\u003cp\u003eThe scripts can be run in any order and can be deleted once they have been run.\u003c/p\u003e\n\u003cdiv class=\"caution\"\u003e\n\u003ch3 class=\"title\"\u003eCaution\u003c/h3\u003e\n\u003cp\u003eIn general it is unsafe to access tables referenced in rebuild scripts until the rebuild scripts have run to completion; doing so could yield incorrect results or poor performance. Tables not referenced in rebuild scripts can be accessed immediately.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eStatistics\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eUnless the \u003ccode class=\"option\"\u003e--no-statistics\u003c/code\u003e option is specified, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will transfer most optimizer statistics from the old cluster to the new cluster. This does not transfer all statistics, such as those created explicitly with \u003ca class=\"xref\" href=\"/docs/18/sql-createstatistics.html\" title=\"CREATE STATISTICS\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE STATISTICS\u003c/span\u003e\u003c/a\u003e, custom statistics added by an extension, or statistics collected by the cumulative statistics system.\u003c/p\u003e\n\u003cp\u003eBecause not all statistics are transferred by \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e, you will be instructed to run commands to regenerate that information at the end of the upgrade. You might need to set connection parameters to match your new cluster.\u003c/p\u003e\n\u003cp\u003eFirst, use \u003ccode class=\"command\"\u003evacuumdb --all --analyze-in-stages --missing-stats-only\u003c/code\u003e to quickly generate minimal optimizer statistics for relations without any. Then, use \u003ccode class=\"command\"\u003evacuumdb --all --analyze-only\u003c/code\u003e to ensure all relations have updated cumulative statistics for triggering vacuum and analyze. For both commands, the use of \u003ccode class=\"option\"\u003e--jobs\u003c/code\u003e can speed it up. If \u003ccode class=\"varname\"\u003evacuum_cost_delay\u003c/code\u003e is set to a non-zero value, this can be overridden to speed up statistics generation using \u003ccode class=\"envar\"\u003ePGOPTIONS\u003c/code\u003e, e.g., \u003ccode class=\"literal\"\u003ePGOPTIONS='-c vacuum_cost_delay=0' vacuumdb ...\u003c/code\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eDelete old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eOnce you are satisfied with the upgrade, you can delete the old cluster's data directories by running the script mentioned when \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e completes. (Automatic deletion is not possible if you have user-defined tablespaces inside the old data directory.) You can also delete the old installation directories (e.g., \u003ccode class=\"filename\"\u003ebin\u003c/code\u003e, \u003ccode class=\"filename\"\u003eshare\u003c/code\u003e).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\" id=\"PGUPGRADE-STEP-REVERT\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eReverting to old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf, after running \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e, you wish to revert to the old cluster, there are several options:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf the \u003ccode class=\"option\"\u003e--check\u003c/code\u003e option was used, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf neither \u003ccode class=\"option\"\u003e--link\u003c/code\u003e nor \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e was used, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf the \u003ccode class=\"option\"\u003e--link\u003c/code\u003e option was used, the data files might be shared between the old and new cluster:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e aborted before linking started, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf you did \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e start the new cluster, the old cluster was unmodified except that, when linking started, a \u003ccode class=\"literal\"\u003e.old\u003c/code\u003e suffix was appended to \u003ccode class=\"filename\"\u003e$PGDATA/global/pg_control\u003c/code\u003e. To reuse the old cluster, remove the \u003ccode class=\"filename\"\u003e.old\u003c/code\u003e suffix from \u003ccode class=\"filename\"\u003e$PGDATA/global/pg_control\u003c/code\u003e; you can then restart the old cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf you did start the new cluster, it has written to shared files and it is unsafe to use the old cluster. The old cluster will need to be restored from backup in this case.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf the \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e option was used, the old cluster might be destructively modified:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e aborts before reporting that the old cluster is no longer safe to start, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e has reported that the old cluster is no longer safe to start, the old cluster was destructively modified. The old cluster will need to be restored from backup in this case.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.8\"\u003e\n\u003ch2\u003eEnvironment\u003c/h2\u003e\n\u003cp\u003eSome environment variables can be used to provide defaults for command-line options:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGBINOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old PostgreSQL executable directory; option \u003ccode class=\"option\"\u003e-b\u003c/code\u003e/\u003ccode class=\"option\"\u003e--old-bindir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGBINNEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new PostgreSQL executable directory; option \u003ccode class=\"option\"\u003e-B\u003c/code\u003e/\u003ccode class=\"option\"\u003e--new-bindir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGDATAOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old database cluster configuration directory; option \u003ccode class=\"option\"\u003e-d\u003c/code\u003e/\u003ccode class=\"option\"\u003e--old-datadir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGDATANEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new database cluster configuration directory; option \u003ccode class=\"option\"\u003e-D\u003c/code\u003e/\u003ccode class=\"option\"\u003e--new-datadir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGPORTOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old cluster port number; option \u003ccode class=\"option\"\u003e-p\u003c/code\u003e/\u003ccode class=\"option\"\u003e--old-port\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGPORTNEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new cluster port number; option \u003ccode class=\"option\"\u003e-P\u003c/code\u003e/\u003ccode class=\"option\"\u003e--new-port\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGSOCKETDIR\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDirectory to use for postmaster sockets during upgrade; option \u003ccode class=\"option\"\u003e-s\u003c/code\u003e/\u003ccode class=\"option\"\u003e--socketdir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGUSER\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCluster's install user name; option \u003ccode class=\"option\"\u003e-U\u003c/code\u003e/\u003ccode class=\"option\"\u003e--username\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.9\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e creates various working files, such as schema dumps, stored within \u003ccode class=\"filename\"\u003epg_upgrade_output.d\u003c/code\u003e in the directory of the new cluster. Each run creates a new subdirectory named with a timestamp formatted as per ISO 8601 (\u003ccode class=\"literal\"\u003e%Y%m%dT%H%M%S\u003c/code\u003e), where all its generated files are stored. \u003ccode class=\"filename\"\u003epg_upgrade_output.d\u003c/code\u003e and its contained files will be removed automatically if \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e completes successfully; but in the event of trouble, the files there may provide useful debugging information.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e launches short-lived postmasters in the old and new data directories. Temporary Unix socket files for communication with these postmasters are, by default, made in the current working directory. In some situations the path name for the current directory might be too long to be a valid socket name. In that case you can use the \u003ccode class=\"option\"\u003e-s\u003c/code\u003e option to put the socket files in some directory with a shorter path name. For security, be sure that that directory is not readable or writable by any other users. (This is not supported on Windows.)\u003c/p\u003e\n\u003cp\u003eAll failure, rebuild, and reindex cases will be reported by \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e if they affect your installation; post-upgrade scripts to rebuild tables and indexes will be generated automatically. If you are trying to automate the upgrade of many clusters, you should find that clusters with identical database schemas require the same post-upgrade steps for all cluster upgrades; this is because the post-upgrade steps are based on the database schemas, and not user data.\u003c/p\u003e\n\u003cp\u003eFor deployment testing, create a schema-only copy of the old cluster, insert dummy data, and upgrade that.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e does not support upgrading of databases containing table columns using these \u003ccode class=\"type\"\u003ereg*\u003c/code\u003e OID-referencing system data types:\u003c/p\u003e\n\u003ctable class=\"simplelist\"\u003e\n\u003ctbody\u003e\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregcollation\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregconfig\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregdictionary\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregnamespace\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregoper\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregoperator\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregproc\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregprocedure\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\u003c/table\u003e\n\u003cp\u003e(\u003ccode class=\"type\"\u003eregclass\u003c/code\u003e, \u003ccode class=\"type\"\u003eregrole\u003c/code\u003e, and \u003ccode class=\"type\"\u003eregtype\u003c/code\u003e can be upgraded.)\u003c/p\u003e\n\u003cp\u003eIf you want to use link mode and you do not want your old cluster to be modified when the new cluster is started, consider using the clone mode. If that is not available, make a copy of the old cluster and upgrade that in link mode. To make a valid copy of the old cluster, use \u003ccode class=\"command\"\u003ersync\u003c/code\u003e to create a dirty copy of the old cluster while the server is running, then shut down the old server and run \u003ccode class=\"command\"\u003ersync --checksum\u003c/code\u003e again to update the copy with any changes to make it consistent. (\u003ccode class=\"option\"\u003e--checksum\u003c/code\u003e is necessary because \u003ccode class=\"command\"\u003ersync\u003c/code\u003e only has file modification-time granularity of one second.) You might want to exclude some files, e.g., \u003ccode class=\"filename\"\u003epostmaster.pid\u003c/code\u003e, as documented in \u003ca class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.4. Making a Base Backup Using the Low Level API\"\u003eSection 25.3.4\u003c/a\u003e. If your file system supports file system snapshots or copy-on-write file copies, you can use that to make a backup of the old cluster and tablespaces, though the snapshot and copies must be created simultaneously or while the database server is down.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.10\"\u003e\n\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/docs/18/app-initdb.html\" title=\"initdb\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003einitdb\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/docs/18/app-pg-ctl.html\" title=\"pg_ctl\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_ctl\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/docs/18/app-pgdump.html\" title=\"pg_dump\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_dump\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/docs/18/app-postgres.html\" title=\"postgres\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epostgres\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","manual_path":"pgupgrade.html","options":[{"description":"the old PostgreSQL executable directory; environment variable PGBINOLD","names":["-b","--old-bindir="],"signature":"-b bindir --old-bindir= bindir","source_url":"/docs/18/pgupgrade.html","summary":"the old PostgreSQL executable directory; environment variable PGBINOLD"},{"description":"the new PostgreSQL executable directory; default is the directory where pg_upgrade resides; environment variable PGBINNEW","names":["-B","--new-bindir="],"signature":"-B bindir --new-bindir= bindir","source_url":"/docs/18/pgupgrade.html","summary":"the new PostgreSQL executable directory; default is the directory where pg_upgrade resides; environment variable PGBINNEW"},{"description":"check clusters only, don't change any data","names":["-c","--check"],"signature":"-c --check","source_url":"/docs/18/pgupgrade.html","summary":"check clusters only, don't change any data"},{"description":"the old database cluster configuration directory; environment variable PGDATAOLD","names":["-d","--old-datadir="],"signature":"-d configdir --old-datadir= configdir","source_url":"/docs/18/pgupgrade.html","summary":"the old database cluster configuration directory; environment variable PGDATAOLD"},{"description":"the new database cluster configuration directory; environment variable PGDATANEW","names":["-D","--new-datadir="],"signature":"-D configdir --new-datadir= configdir","source_url":"/docs/18/pgupgrade.html","summary":"the new database cluster configuration directory; environment variable PGDATANEW"},{"description":"number of simultaneous connections and processes/threads to use","names":["-j njobs","--jobs= njobs"],"signature":"-j njobs --jobs= njobs","source_url":"/docs/18/pgupgrade.html","summary":"number of simultaneous connections and processes/threads to use"},{"description":"use hard links instead of copying files to the new cluster","names":["-k","--link"],"signature":"-k --link","source_url":"/docs/18/pgupgrade.html","summary":"use hard links instead of copying files to the new cluster"},{"description":"By default, pg_upgrade will wait for all files of the upgraded cluster to be written safely to disk. This option causes pg_upgrade to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation.","names":["-N","--no-sync"],"signature":"-N --no-sync","source_url":"/docs/18/pgupgrade.html","summary":"By default, pg_upgrade will wait for all files of the upgraded cluster to be written safely to disk. This option causes pg_upgrade to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation."},{"description":"options to be passed directly to the old postgres command; multiple option invocations are appended","names":["-o","--old-options"],"signature":"-o options --old-options options","source_url":"/docs/18/pgupgrade.html","summary":"options to be passed directly to the old postgres command; multiple option invocations are appended"},{"description":"options to be passed directly to the new postgres command; multiple option invocations are appended","names":["-O","--new-options"],"signature":"-O options --new-options options","source_url":"/docs/18/pgupgrade.html","summary":"options to be passed directly to the new postgres command; multiple option invocations are appended"},{"description":"the old cluster port number; environment variable PGPORTOLD","names":["-p","--old-port="],"signature":"-p port --old-port= port","source_url":"/docs/18/pgupgrade.html","summary":"the old cluster port number; environment variable PGPORTOLD"},{"description":"the new cluster port number; environment variable PGPORTNEW","names":["-P","--new-port="],"signature":"-P port --new-port= port","source_url":"/docs/18/pgupgrade.html","summary":"the new cluster port number; environment variable PGPORTNEW"},{"description":"retain SQL and log files even after successful completion","names":["-r","--retain"],"signature":"-r --retain","source_url":"/docs/18/pgupgrade.html","summary":"retain SQL and log files even after successful completion"},{"description":"directory to use for postmaster sockets during upgrade; default is current working directory; environment variable PGSOCKETDIR","names":["-s","--socketdir="],"signature":"-s dir --socketdir= dir","source_url":"/docs/18/pgupgrade.html","summary":"directory to use for postmaster sockets during upgrade; default is current working directory; environment variable PGSOCKETDIR"},{"description":"cluster's install user name; environment variable PGUSER","names":["-U","--username="],"signature":"-U username --username= username","source_url":"/docs/18/pgupgrade.html","summary":"cluster's install user name; environment variable PGUSER"},{"description":"enable verbose internal logging","names":["-v","--verbose"],"signature":"-v --verbose","source_url":"/docs/18/pgupgrade.html","summary":"enable verbose internal logging"},{"description":"display version information, then exit","names":["-V","--version"],"signature":"-V --version","source_url":"/docs/18/pgupgrade.html","summary":"display version information, then exit"},{"description":"Use efficient file cloning (also known as “ reflinks ” on some systems) instead of copying files to the new cluster. This can result in near-instantaneous copying of the data files, giving the speed advantages of -k / --link while leaving the old cluster untouched. File cloning is only supported on some operating systems and file systems. If it is selected but not supported, the pg_upgrade run will error. At present, it is supported on Linux (kernel 4.5 or later) with Btrfs and XFS (on file systems created with reflink support), and on macOS with APFS.","names":["--clone"],"signature":"--clone","source_url":"/docs/18/pgupgrade.html","summary":"Use efficient file cloning (also known as “ reflinks ” on some systems) instead of copying files to the new cluster. This can result in near-instantaneous copying of the data files, giving the speed advantages of -k / --link while leaving the old cluster untouched."},{"description":"Copy files to the new cluster. This is the default. (See also --link , --clone , --copy-file-range , and --swap .)","names":["--copy"],"signature":"--copy","source_url":"/docs/18/pgupgrade.html","summary":"Copy files to the new cluster. This is the default. (See also --link , --clone , --copy-file-range , and --swap .)"},{"description":"Use the copy_file_range system call for efficient copying. On some file systems this gives results similar to --clone , sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path. At present, it is supported on Linux and FreeBSD.","names":["--copy-file-range"],"signature":"--copy-file-range","source_url":"/docs/18/pgupgrade.html","summary":"Use the copy_file_range system call for efficient copying. On some file systems this gives results similar to --clone , sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path. At present, it is supported on Linux and FreeBSD."},{"description":"Do not restore statistics from the old cluster into the new cluster.","names":["--no-statistics"],"signature":"--no-statistics","source_url":"/docs/18/pgupgrade.html","summary":"Do not restore statistics from the old cluster into the new cluster."},{"description":"Manually set the default char signedness of new clusters. Possible values are signed and unsigned . In the C language, the default signedness of the char type (when not explicitly specified) varies across platforms. For example, char defaults to signed char on x86 CPUs but to unsigned char on ARM CPUs. Starting from PostgreSQL 18, database clusters maintain their own default char signedness setting, which can be used to ensure consistent behavior across platforms with different default char signedness. By default, pg_upgrade preserves the char signedness setting when upgrading from an existing cluster. However, when upgrading from PostgreSQL 17 or earlier, pg_upgrade adopts the char signedness of the platform on which it was built. This option allows you to explicitly set the default char signedness for the new cluster, overriding any inherited values. There are two specific scenarios where this option is relevant: If you are planning to migrate to a different platform after the upgrade, you should not use this option. The default behavior is right in this case. Instead, perform the upgrade on the original platform without this flag, and then migrate the cluster afterward. This is the recommended and safest approach. If you have already migrated the cluster to a platform with different char signedness (for example, from an x86-based system to an ARM-based system), you should use this option to specify the signedness matching the original platform's default char signedness. Additionally, it's essential not to modify any data files between migrating data files and running pg_upgrade . pg_upgrade should be the first operation that starts the cluster on the new platform.","names":["--set-char-signedness="],"signature":"--set-char-signedness= option","source_url":"/docs/18/pgupgrade.html","summary":"Manually set the default char signedness of new clusters. Possible values are signed and unsigned ."},{"description":"Move the data directories from the old cluster to the new cluster. Then, 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. Therefore, it is recommended to use --sync-method=fsync with --swap . Additionally, once the file transfer step begins, the old cluster will be destructively modified and therefore will no longer be safe to start. See Step 17 for details.","names":["--swap"],"signature":"--swap","source_url":"/docs/18/pgupgrade.html","summary":"Move the data directories from the old cluster to the new cluster. Then, 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."},{"description":"When set to fsync , which is the default, pg_upgrade will recursively open and synchronize all files in the upgraded cluster's data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file systems that contain the upgraded cluster's data directory, its WAL files, and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used.","names":["--sync-method="],"signature":"--sync-method= method","source_url":"/docs/18/pgupgrade.html","summary":"When set to fsync , which is the default, pg_upgrade will recursively open and synchronize all files in the upgraded cluster's data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace."},{"description":"show help, then exit","names":["-?","--help"],"signature":"-? --help","source_url":"/docs/18/pgupgrade.html","summary":"show help, then exit"}],"related":[],"release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[],"signature":"pg_upgrade -b oldbindir [ -B newbindir ] -d oldconfigdir -D newconfigdir [ option ...]","sources":[{"anchor":"","file":"pgupgrade.html","label":"18.6 English manual · pgupgrade.html","sha256":"2e660b507e9708faa548f04934c0108f501d26931606e9c14dfbfbb1e5ec7917","url":"/docs/18/pgupgrade.html"},{"anchor":"","file":"reference-server.html","label":"Server applications inventory","sha256":"e9f8bbcc8e3641fadd1d20991e8aad6b532155b786ba5a1b7b364ec4f1a5bef3","url":"/docs/18/reference-server.html"}],"synopsis":["pg_upgrade -b oldbindir [ -B newbindir ] -d oldconfigdir -D newconfigdir [ option ...]"],"tables":[{"columns":[{"key":"signature","label":"Option and arguments"},{"key":"summary","label":"Description"}],"key":"options","rows":[{"signature":{"text":"-b bindir --old-bindir= bindir","url":"/docs/18/pgupgrade.html"},"summary":"the old PostgreSQL executable directory; environment variable PGBINOLD"},{"signature":{"text":"-B bindir --new-bindir= bindir","url":"/docs/18/pgupgrade.html"},"summary":"the new PostgreSQL executable directory; default is the directory where pg_upgrade resides; environment variable PGBINNEW"},{"signature":{"text":"-c --check","url":"/docs/18/pgupgrade.html"},"summary":"check clusters only, don't change any data"},{"signature":{"text":"-d configdir --old-datadir= configdir","url":"/docs/18/pgupgrade.html"},"summary":"the old database cluster configuration directory; environment variable PGDATAOLD"},{"signature":{"text":"-D configdir --new-datadir= configdir","url":"/docs/18/pgupgrade.html"},"summary":"the new database cluster configuration directory; environment variable PGDATANEW"},{"signature":{"text":"-j njobs --jobs= njobs","url":"/docs/18/pgupgrade.html"},"summary":"number of simultaneous connections and processes/threads to use"},{"signature":{"text":"-k --link","url":"/docs/18/pgupgrade.html"},"summary":"use hard links instead of copying files to the new cluster"},{"signature":{"text":"-N --no-sync","url":"/docs/18/pgupgrade.html"},"summary":"By default, pg_upgrade will wait for all files of the upgraded cluster to be written safely to disk. This option causes pg_upgrade to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation."},{"signature":{"text":"-o options --old-options options","url":"/docs/18/pgupgrade.html"},"summary":"options to be passed directly to the old postgres command; multiple option invocations are appended"},{"signature":{"text":"-O options --new-options options","url":"/docs/18/pgupgrade.html"},"summary":"options to be passed directly to the new postgres command; multiple option invocations are appended"},{"signature":{"text":"-p port --old-port= port","url":"/docs/18/pgupgrade.html"},"summary":"the old cluster port number; environment variable PGPORTOLD"},{"signature":{"text":"-P port --new-port= port","url":"/docs/18/pgupgrade.html"},"summary":"the new cluster port number; environment variable PGPORTNEW"},{"signature":{"text":"-r --retain","url":"/docs/18/pgupgrade.html"},"summary":"retain SQL and log files even after successful completion"},{"signature":{"text":"-s dir --socketdir= dir","url":"/docs/18/pgupgrade.html"},"summary":"directory to use for postmaster sockets during upgrade; default is current working directory; environment variable PGSOCKETDIR"},{"signature":{"text":"-U username --username= username","url":"/docs/18/pgupgrade.html"},"summary":"cluster's install user name; environment variable PGUSER"},{"signature":{"text":"-v --verbose","url":"/docs/18/pgupgrade.html"},"summary":"enable verbose internal logging"},{"signature":{"text":"-V --version","url":"/docs/18/pgupgrade.html"},"summary":"display version information, then exit"},{"signature":{"text":"--clone","url":"/docs/18/pgupgrade.html"},"summary":"Use efficient file cloning (also known as “ reflinks ” on some systems) instead of copying files to the new cluster. This can result in near-instantaneous copying of the data files, giving the speed advantages of -k / --link while leaving the old cluster untouched."},{"signature":{"text":"--copy","url":"/docs/18/pgupgrade.html"},"summary":"Copy files to the new cluster. This is the default. (See also --link , --clone , --copy-file-range , and --swap .)"},{"signature":{"text":"--copy-file-range","url":"/docs/18/pgupgrade.html"},"summary":"Use the copy_file_range system call for efficient copying. On some file systems this gives results similar to --clone , sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path. At present, it is supported on Linux and FreeBSD."},{"signature":{"text":"--no-statistics","url":"/docs/18/pgupgrade.html"},"summary":"Do not restore statistics from the old cluster into the new cluster."},{"signature":{"text":"--set-char-signedness= option","url":"/docs/18/pgupgrade.html"},"summary":"Manually set the default char signedness of new clusters. Possible values are signed and unsigned ."},{"signature":{"text":"--swap","url":"/docs/18/pgupgrade.html"},"summary":"Move the data directories from the old cluster to the new cluster. Then, 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."},{"signature":{"text":"--sync-method= method","url":"/docs/18/pgupgrade.html"},"summary":"When set to fsync , which is the default, pg_upgrade will recursively open and synchronize all files in the upgraded cluster's data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace."},{"signature":{"text":"-? --help","url":"/docs/18/pgupgrade.html"},"summary":"show help, then exit"}],"title":"Documented options"},{"columns":[{"key":"name","label":"Variable"},{"key":"description","label":"Meaning"}],"key":"environment","rows":[{"description":"The old PostgreSQL executable directory; option -b / --old-bindir .","name":"PGBINOLD"},{"description":"The new PostgreSQL executable directory; option -B / --new-bindir .","name":"PGBINNEW"},{"description":"The old database cluster configuration directory; option -d / --old-datadir .","name":"PGDATAOLD"},{"description":"The new database cluster configuration directory; option -D / --new-datadir .","name":"PGDATANEW"},{"description":"The old cluster port number; option -p / --old-port .","name":"PGPORTOLD"},{"description":"The new cluster port number; option -P / --new-port .","name":"PGPORTNEW"},{"description":"Directory to use for postmaster sockets during upgrade; option -s / --socketdir .","name":"PGSOCKETDIR"},{"description":"Cluster's install user name; option -U / --username .","name":"PGUSER"}],"title":"Environment variables"}]},"ManualEvidence":{"manual_path":"pgupgrade.html","release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"anchor":"","file":"pgupgrade.html","label":"18.6 English manual · pgupgrade.html","sha256":"2e660b507e9708faa548f04934c0108f501d26931606e9c14dfbfbb1e5ec7917","url":"/docs/18/pgupgrade.html"},{"anchor":"","file":"reference-server.html","label":"Server applications inventory","sha256":"e9f8bbcc8e3641fadd1d20991e8aad6b532155b786ba5a1b7b364ec4f1a5bef3","url":"/docs/18/reference-server.html"}]},"MeasuredEvidence":{}},"Text":{"Collection":"tool","Key":"pg-upgrade","SourceDatabase":"center","Version":"18","Locale":"en","Title":"pg_upgrade","Summary":"pg_upgrade — upgrade a PostgreSQL server instance","BodyHTML":"\u003cdiv\u003e\u003cdiv id=\"PGUPGRADE\"\u003e\n\u003cdiv\u003e\u003c/div\u003e\n\u003cdiv\u003e\n\u003ch2\u003e\u003cspan\u003e\u003cspan\u003epg_upgrade\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_upgrade — upgrade a \u003cspan\u003ePostgreSQL\u003c/span\u003e server instance\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv\u003e\n\u003cp id=\"id-1.9.5.13.4.1\"\u003e\u003ccode\u003epg_upgrade\u003c/code\u003e \u003ccode\u003e-b\u003c/code\u003e \u003cem\u003e\u003ccode\u003eoldbindir\u003c/code\u003e\u003c/em\u003e [\u003ccode\u003e-B\u003c/code\u003e \u003cem\u003e\u003ccode\u003enewbindir\u003c/code\u003e\u003c/em\u003e] \u003ccode\u003e-d\u003c/code\u003e \u003cem\u003e\u003ccode\u003eoldconfigdir\u003c/code\u003e\u003c/em\u003e \u003ccode\u003e-D\u003c/code\u003e \u003cem\u003e\u003ccode\u003enewconfigdir\u003c/code\u003e\u003c/em\u003e [\u003cem\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...]\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.13.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003epg_upgrade\u003c/span\u003e (formerly called \u003cspan\u003epg_migrator\u003c/span\u003e) allows data stored in \u003cspan\u003ePostgreSQL\u003c/span\u003e data files to be upgraded to a later \u003cspan\u003ePostgreSQL\u003c/span\u003e major version without the data dump/restore typically required for major version upgrades, e.g., from 12.14 to 13.10 or from 14.9 to 15.5. It is not required for minor version upgrades, e.g., from 12.7 to 12.8 or from 14.1 to 14.5.\u003c/p\u003e\n\u003cp\u003eMajor PostgreSQL releases regularly add new features that often change the layout of the system tables, but the internal data storage format rarely changes. \u003cspan\u003epg_upgrade\u003c/span\u003e uses this fact to perform rapid upgrades by creating new system tables and simply reusing the old user data files. If a future major release ever changes the data storage format in a way that makes the old data format unreadable, \u003cspan\u003epg_upgrade\u003c/span\u003e will not be usable for such upgrades. (The community will attempt to avoid such situations.)\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003epg_upgrade\u003c/span\u003e does its best to make sure the old and new clusters are binary-compatible, e.g., by checking for compatible compile-time settings, including 32/64-bit binaries. It is important that any external modules are also binary compatible, though this cannot be checked by \u003cspan\u003epg_upgrade\u003c/span\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003epg_upgrade\u003c/span\u003e supports upgrades from 9.2.X and later to the current major release of \u003cspan\u003ePostgreSQL\u003c/span\u003e, including snapshot and beta releases.\u003c/p\u003e\n\u003cdiv\u003e\n\u003ch3\u003eWarning\u003c/h3\u003e\n\u003cp\u003eUpgrading a cluster causes the destination to execute arbitrary code of the source superusers\u0026#39; choice. Ensure that the source superusers are trusted before upgrading.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.13.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003epg_upgrade\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-b\u003c/code\u003e \u003cem\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--old-bindir=\u003c/code\u003e\u003cem\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old PostgreSQL executable directory; environment variable \u003ccode\u003ePGBINOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-B\u003c/code\u003e \u003cem\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--new-bindir=\u003c/code\u003e\u003cem\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new PostgreSQL executable directory; default is the directory where \u003cspan\u003epg_upgrade\u003c/span\u003e resides; environment variable \u003ccode\u003ePGBINNEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-c\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--check\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003echeck clusters only, don\u0026#39;t change any data\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-d\u003c/code\u003e \u003cem\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--old-datadir=\u003c/code\u003e\u003cem\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old database cluster configuration directory; environment variable \u003ccode\u003ePGDATAOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-D\u003c/code\u003e \u003cem\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--new-datadir=\u003c/code\u003e\u003cem\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new database cluster configuration directory; environment variable \u003ccode\u003ePGDATANEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-j \u003cem\u003e\u003ccode\u003enjobs\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--jobs=\u003cem\u003e\u003ccode\u003enjobs\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003enumber of simultaneous connections and processes/threads to use\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-k\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--link\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003euse hard links instead of copying files to the new cluster\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-N\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--no-sync\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eBy default, \u003ccode\u003epg_upgrade\u003c/code\u003e will wait for all files of the upgraded cluster to be written safely to disk. This option causes \u003ccode\u003epg_upgrade\u003c/code\u003e to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-o\u003c/code\u003e \u003cem\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--old-options\u003c/code\u003e \u003cem\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eoptions to be passed directly to the old \u003ccode\u003epostgres\u003c/code\u003e command; multiple option invocations are appended\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-O\u003c/code\u003e \u003cem\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--new-options\u003c/code\u003e \u003cem\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eoptions to be passed directly to the new \u003ccode\u003epostgres\u003c/code\u003e command; multiple option invocations are appended\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-p\u003c/code\u003e \u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--old-port=\u003c/code\u003e\u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old cluster port number; environment variable \u003ccode\u003ePGPORTOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-P\u003c/code\u003e \u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--new-port=\u003c/code\u003e\u003cem\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new cluster port number; environment variable \u003ccode\u003ePGPORTNEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-r\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--retain\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eretain SQL and log files even after successful completion\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-s\u003c/code\u003e \u003cem\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--socketdir=\u003c/code\u003e\u003cem\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003edirectory to use for postmaster sockets during upgrade; default is current working directory; environment variable \u003ccode\u003ePGSOCKETDIR\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-U\u003c/code\u003e \u003cem\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--username=\u003c/code\u003e\u003cem\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ecluster\u0026#39;s install user name; environment variable \u003ccode\u003ePGUSER\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-v\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--verbose\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eenable verbose internal logging\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003edisplay version information, then exit\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--clone\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse efficient file cloning (also known as \u003cspan\u003e“\u003cspan\u003ereflinks\u003c/span\u003e”\u003c/span\u003e on some systems) instead of copying files to the new cluster. This can result in near-instantaneous copying of the data files, giving the speed advantages of \u003ccode\u003e-k\u003c/code\u003e/\u003ccode\u003e--link\u003c/code\u003e while leaving the old cluster untouched.\u003c/p\u003e\n\u003cp\u003eFile cloning is only supported on some operating systems and file systems. If it is selected but not supported, the \u003cspan\u003epg_upgrade\u003c/span\u003e run will error. At present, it is supported on Linux (kernel 4.5 or later) with Btrfs and XFS (on file systems created with reflink support), and on macOS with APFS.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--copy\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCopy files to the new cluster. This is the default. (See also \u003ccode\u003e--link\u003c/code\u003e, \u003ccode\u003e--clone\u003c/code\u003e, \u003ccode\u003e--copy-file-range\u003c/code\u003e, and \u003ccode\u003e--swap\u003c/code\u003e.)\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--copy-file-range\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse the \u003ccode\u003ecopy_file_range\u003c/code\u003e system call for efficient copying. On some file systems this gives results similar to \u003ccode\u003e--clone\u003c/code\u003e, sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path. At present, it is supported on Linux and FreeBSD.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--no-statistics\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDo not restore statistics from the old cluster into the new cluster.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--set-char-signedness=\u003c/code\u003e\u003cem\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eManually set the default char signedness of new clusters. Possible values are \u003ccode\u003esigned\u003c/code\u003e and \u003ccode\u003eunsigned\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eIn the C language, the default signedness of the \u003ccode\u003echar\u003c/code\u003e type (when not explicitly specified) varies across platforms. For example, \u003ccode\u003echar\u003c/code\u003e defaults to \u003ccode\u003esigned char\u003c/code\u003e on x86 CPUs but to \u003ccode\u003eunsigned char\u003c/code\u003e on ARM CPUs.\u003c/p\u003e\n\u003cp\u003eStarting from \u003cspan\u003ePostgreSQL\u003c/span\u003e 18, database clusters maintain their own default char signedness setting, which can be used to ensure consistent behavior across platforms with different default char signedness. By default, \u003cspan\u003epg_upgrade\u003c/span\u003e preserves the char signedness setting when upgrading from an existing cluster. However, when upgrading from \u003cspan\u003ePostgreSQL\u003c/span\u003e 17 or earlier, \u003cspan\u003epg_upgrade\u003c/span\u003e adopts the char signedness of the platform on which it was built.\u003c/p\u003e\n\u003cp\u003eThis option allows you to explicitly set the default char signedness for the new cluster, overriding any inherited values. There are two specific scenarios where this option is relevant:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003eIf you are planning to migrate to a different platform after the upgrade, you should not use this option. The default behavior is right in this case. Instead, perform the upgrade on the original platform without this flag, and then migrate the cluster afterward. This is the recommended and safest approach.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf you have already migrated the cluster to a platform with different char signedness (for example, from an x86-based system to an ARM-based system), you should use this option to specify the signedness matching the original platform\u0026#39;s default char signedness. Additionally, it\u0026#39;s essential not to modify any data files between migrating data files and running \u003ccode\u003epg_upgrade\u003c/code\u003e. \u003ccode\u003epg_upgrade\u003c/code\u003e should be the first operation that starts the cluster on the new platform.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--swap\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eMove the data directories from the old cluster to the new cluster. Then, replace the catalog files with those generated for the new cluster. This mode can outperform \u003ccode\u003e--link\u003c/code\u003e, \u003ccode\u003e--clone\u003c/code\u003e, \u003ccode\u003e--copy\u003c/code\u003e, and \u003ccode\u003e--copy-file-range\u003c/code\u003e, especially on clusters with many relations.\u003c/p\u003e\n\u003cp\u003eHowever, this mode creates many garbage files in the old cluster, which can prolong the file synchronization step if \u003ccode\u003e--sync-method=syncfs\u003c/code\u003e is used. Therefore, it is recommended to use \u003ccode\u003e--sync-method=fsync\u003c/code\u003e with \u003ccode\u003e--swap\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eAdditionally, once the file transfer step begins, the old cluster will be destructively modified and therefore will no longer be safe to start. See \u003ca href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REVERT\" title=\"Reverting to old cluster\" rel=\"nofollow\"\u003eStep 17\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e--sync-method=\u003c/code\u003e\u003cem\u003e\u003ccode\u003emethod\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWhen set to \u003ccode\u003efsync\u003c/code\u003e, which is the default, \u003ccode\u003epg_upgrade\u003c/code\u003e will recursively open and synchronize all files in the upgraded cluster\u0026#39;s data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace.\u003c/p\u003e\n\u003cp\u003eOn Linux, \u003ccode\u003esyncfs\u003c/code\u003e may be used instead to ask the operating system to synchronize the whole file systems that contain the upgraded cluster\u0026#39;s data directory, its WAL files, and each tablespace. See \u003ca href=\"/docs/18/runtime-config-error-handling.html#GUC-RECOVERY-INIT-SYNC-METHOD\" rel=\"nofollow\"\u003erecovery_init_sync_method\u003c/a\u003e for information about the caveats to be aware of when using \u003ccode\u003esyncfs\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThis option has no effect when \u003ccode\u003e--no-sync\u003c/code\u003e is used.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eshow help, then exit\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.13.7\"\u003e\n\u003ch2\u003eUsage\u003c/h2\u003e\n\u003cp\u003eThese are the steps to perform an upgrade with \u003cspan\u003epg_upgrade\u003c/span\u003e:\u003c/p\u003e\n\u003cdiv\u003e\n\u003ch3\u003eNote\u003c/h3\u003e\n\u003cp\u003eThe steps to upgrade \u003ca href=\"/docs/18/glossary.html#GLOSSARY-LOGICAL-REPLICATION-CLUSTER\" rel=\"nofollow\"\u003e\u003c/a\u003e\u003ca href=\"/docs/18/glossary.html#GLOSSARY-LOGICAL-REPLICATION-CLUSTER\" title=\"Logical replication cluster\" rel=\"nofollow\"\u003elogical replication clusters\u003c/a\u003e are not covered here; refer to \u003ca href=\"/docs/18/logical-replication-upgrade.html\" rel=\"nofollow\"\u003eSection 29.13\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eOptionally move the old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you are using a version-specific installation directory, e.g., \u003ccode\u003e/opt/PostgreSQL/18\u003c/code\u003e, you do not need to move the old cluster. The graphical installers all use version-specific installation directories.\u003c/p\u003e\n\u003cp\u003eIf your installation directory is not version-specific, e.g., \u003ccode\u003e/usr/local/pgsql\u003c/code\u003e, it is necessary to move the current PostgreSQL install directory so it does not interfere with the new \u003cspan\u003ePostgreSQL\u003c/span\u003e installation. Once the current \u003cspan\u003ePostgreSQL\u003c/span\u003e server is shut down, it is safe to rename the PostgreSQL installation directory; assuming the old directory is \u003ccode\u003e/usr/local/pgsql\u003c/code\u003e, you can do:\u003c/p\u003e\n\u003cpre\u003emv /usr/local/pgsql /usr/local/pgsql.old\n\u003c/pre\u003e\n\u003cp\u003eto rename the directory.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eFor source installs, build the new version\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eBuild the new PostgreSQL source with \u003ccode\u003econfigure\u003c/code\u003e flags that are compatible with the old cluster. \u003cspan\u003epg_upgrade\u003c/span\u003e will check \u003ccode\u003epg_controldata\u003c/code\u003e to make sure all settings are compatible before starting the upgrade.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eInstall the new PostgreSQL binaries\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInstall the new server\u0026#39;s binaries and support files. \u003cspan\u003epg_upgrade\u003c/span\u003e is included in a default installation.\u003c/p\u003e\n\u003cp\u003eFor source installs, if you wish to install the new server in a custom location, use the \u003ccode\u003eprefix\u003c/code\u003e variable:\u003c/p\u003e\n\u003cpre\u003emake prefix=/usr/local/pgsql.new install\n\u003c/pre\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eInitialize the new PostgreSQL cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInitialize the new cluster using \u003ccode\u003einitdb\u003c/code\u003e. Again, use compatible \u003ccode\u003einitdb\u003c/code\u003e flags that match the old cluster. Many prebuilt installers do this step automatically. There is no need to start the new cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eInstall extension shared object files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMany extensions and custom modules, whether from \u003ccode\u003econtrib\u003c/code\u003e or another source, use shared object files (or DLLs), e.g., \u003ccode\u003epgcrypto.so\u003c/code\u003e. If the old cluster used these, shared object files matching the new server binary must be installed in the new cluster, usually via operating system commands. Do not load the schema definitions, e.g., \u003ccode\u003eCREATE EXTENSION pgcrypto\u003c/code\u003e, because these will be duplicated from the old cluster. If extension updates are available, \u003cspan\u003epg_upgrade\u003c/span\u003e will report this and create a script that can be run later to update them.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eCopy custom full-text search files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eCopy any custom full text search files (dictionary, synonym, thesaurus, stop words) from the old to the new cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eAdjust authentication\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003epg_upgrade\u003c/code\u003e will connect to the old and new servers several times, so you might want to set authentication to \u003ccode\u003epeer\u003c/code\u003e in \u003ccode\u003epg_hba.conf\u003c/code\u003e or use a \u003ccode\u003e~/.pgpass\u003c/code\u003e file (see \u003ca href=\"/docs/18/libpq-pgpass.html\" rel=\"nofollow\"\u003eSection 32.16\u003c/a\u003e).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eStop both servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure both database servers are stopped using, on Unix, e.g.:\u003c/p\u003e\n\u003cpre\u003epg_ctl -D /opt/PostgreSQL/12 stop\npg_ctl -D /opt/PostgreSQL/18 stop\n\u003c/pre\u003e\n\u003cp\u003eor on Windows, using the proper service names:\u003c/p\u003e\n\u003cpre\u003eNET STOP postgresql-12\nNET STOP postgresql-18\n\u003c/pre\u003e\n\u003cp\u003eStreaming replication and log-shipping standby servers must be running during this shutdown so they receive all changes.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003ePrepare for standby server upgrades\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you are upgrading standby servers using methods outlined in section \u003ca href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REPLICAS\" title=\"Upgrade streaming replication and log-shipping standby servers\" rel=\"nofollow\"\u003eStep 11\u003c/a\u003e, verify that the old standby servers are caught up by running \u003cspan\u003epg_controldata\u003c/span\u003e against the old primary and standby clusters. Verify that the \u003cspan\u003e“\u003cspan\u003eLatest checkpoint location\u003c/span\u003e”\u003c/span\u003e values match in all clusters. Also, make sure \u003ccode\u003ewal_level\u003c/code\u003e is not set to \u003ccode\u003eminimal\u003c/code\u003e in the \u003ccode\u003epostgresql.conf\u003c/code\u003e file on the new primary cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eRun \u003cspan\u003epg_upgrade\u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eAlways run the \u003cspan\u003epg_upgrade\u003c/span\u003e binary of the new server, not the old one. \u003cspan\u003epg_upgrade\u003c/span\u003e requires the specification of the old and new cluster\u0026#39;s data and executable (\u003ccode\u003ebin\u003c/code\u003e) directories. You can also specify user and port values, and whether you want the data files linked, cloned, or swapped instead of the default copy behavior.\u003c/p\u003e\n\u003cp\u003eIf you use link mode, the upgrade will be much faster (no file copying) and use less disk space, but you will not be able to access your old cluster once you start the new cluster after the upgrade. Link mode also requires that the old and new cluster data directories be in the same file system. (Tablespaces and \u003ccode\u003epg_wal\u003c/code\u003e can be on different file systems.) Clone mode provides the same speed and disk space advantages but does not cause the old cluster to be unusable once the new cluster is started. Clone mode also requires that the old and new data directories be in the same file system. This mode is only available on certain operating systems and file systems. Swap mode may be the fastest if there are many relations, but you will not be able to access your old cluster once the file transfer step begins. Swap mode also requires that the old and new cluster data directories be in the same file system.\u003c/p\u003e\n\u003cp\u003eSetting \u003ccode\u003e--jobs\u003c/code\u003e to 2 or higher allows pg_upgrade to process multiple databases and tablespaces in parallel. A good starting point is the number of CPU cores on the machine. This option can substantially reduce the upgrade time for multi-database and multi-tablespace servers.\u003c/p\u003e\n\u003cp\u003eFor Windows users, you must be logged into an administrative account, and then run \u003cspan\u003epg_upgrade\u003c/span\u003e with quoted directories, e.g.:\u003c/p\u003e\n\u003cpre\u003epg_upgrade.exe\n        --old-datadir \u0026#34;C:/Program Files/PostgreSQL/12/data\u0026#34;\n        --new-datadir \u0026#34;C:/Program Files/PostgreSQL/18/data\u0026#34;\n        --old-bindir \u0026#34;C:/Program Files/PostgreSQL/12/bin\u0026#34;\n        --new-bindir \u0026#34;C:/Program Files/PostgreSQL/18/bin\u0026#34;\n\u003c/pre\u003e\n\u003cp\u003eOnce started, \u003ccode\u003epg_upgrade\u003c/code\u003e will verify the two clusters are compatible and then do the upgrade. You can use \u003ccode\u003epg_upgrade --check\u003c/code\u003e to perform only the checks, even if the old server is still running. \u003ccode\u003epg_upgrade --check\u003c/code\u003e will also outline any manual adjustments you will need to make after the upgrade. If you are going to be using link, clone, copy-file-range, or swap mode, you should use the option \u003ccode\u003e--link\u003c/code\u003e, \u003ccode\u003e--clone\u003c/code\u003e, \u003ccode\u003e--copy-file-range\u003c/code\u003e, or \u003ccode\u003e--swap\u003c/code\u003e with \u003ccode\u003e--check\u003c/code\u003e to enable mode-specific checks. \u003ccode\u003epg_upgrade\u003c/code\u003e requires write permission in the current directory.\u003c/p\u003e\n\u003cp\u003eObviously, no one should be accessing the clusters during the upgrade. \u003cspan\u003epg_upgrade\u003c/span\u003e defaults to running servers on port 50432 to avoid unintended client connections. You can use the same port number for both clusters when doing an upgrade because the old and new clusters will not be running at the same time. However, when checking an old running server, the old and new port numbers must be different.\u003c/p\u003e\n\u003cp\u003eIf an error occurs while restoring the database schema, \u003ccode\u003epg_upgrade\u003c/code\u003e will exit and you will have to revert to the old cluster as outlined in \u003ca href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REVERT\" title=\"Reverting to old cluster\" rel=\"nofollow\"\u003eStep 17\u003c/a\u003e below. To try \u003ccode\u003epg_upgrade\u003c/code\u003e again, you will need to modify the old cluster so the pg_upgrade schema restore succeeds. If the problem is a \u003ccode\u003econtrib\u003c/code\u003e module, you might need to uninstall the \u003ccode\u003econtrib\u003c/code\u003e module from the old cluster and install it in the new cluster after the upgrade, assuming the module is not being used to store user data.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"PGUPGRADE-STEP-REPLICAS\"\u003e\n\u003cp\u003e\u003cstrong\u003eUpgrade streaming replication and log-shipping standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you used link mode and have Streaming Replication (see \u003ca href=\"/docs/18/warm-standby.html#STREAMING-REPLICATION\" rel=\"nofollow\"\u003eSection 26.2.5\u003c/a\u003e) or Log-Shipping (see \u003ca href=\"/docs/18/warm-standby.html\" rel=\"nofollow\"\u003eSection 26.2\u003c/a\u003e) standby servers, you can follow these steps to quickly upgrade them. You will not be running \u003cspan\u003epg_upgrade\u003c/span\u003e on the standby servers, but rather \u003cspan\u003ersync\u003c/span\u003e on the primary. Do not start any servers yet.\u003c/p\u003e\n\u003cp\u003eIf you did \u003cspan\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e use link mode, do not have or do not want to use \u003cspan\u003ersync\u003c/span\u003e, or want an easier solution, skip the instructions in this section and simply recreate the standby servers once \u003cspan\u003epg_upgrade\u003c/span\u003e completes and the new primary is running.\u003c/p\u003e\n\u003cdiv\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eInstall the new PostgreSQL binaries on standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure the new binaries and support files are installed on all standby servers.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eMake sure the new standby data directories do \u003cspan\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e exist\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure the new standby data directories do \u003cspan\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e exist or are empty. If \u003cspan\u003einitdb\u003c/span\u003e was run, delete the standby servers\u0026#39; new data directories.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eInstall extension shared object files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInstall the same extension shared object files on the new standbys that you installed in the new primary cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eStop standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf the standby servers are still running, stop them now using the above instructions.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eSave configuration files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eSave any configuration files from the old standbys\u0026#39; configuration directories you need to keep, e.g., \u003ccode\u003epostgresql.conf\u003c/code\u003e (and any files included by it), \u003ccode\u003epostgresql.auto.conf\u003c/code\u003e, \u003ccode\u003epg_hba.conf\u003c/code\u003e, because these will be overwritten or removed in the next step.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eRun \u003cspan\u003ersync\u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eWhen using link mode, standby servers can be quickly upgraded using \u003cspan\u003ersync\u003c/span\u003e. To accomplish this, from a directory on the primary server that is above the old and new database cluster directories, run this on the \u003cspan\u003e\u003cem\u003eprimary\u003c/em\u003e\u003c/span\u003e for each standby server:\u003c/p\u003e\n\u003cpre\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive old_cluster new_cluster remote_dir\n\u003c/pre\u003e\n\u003cp\u003ewhere \u003ccode\u003eold_cluster\u003c/code\u003e and \u003ccode\u003enew_cluster\u003c/code\u003e are relative to the current directory on the primary, and \u003ccode\u003eremote_dir\u003c/code\u003e is \u003cspan\u003e\u003cem\u003eabove\u003c/em\u003e\u003c/span\u003e the old and new cluster directories on the standby. The directory structure under the specified directories on the primary and standbys must match. Consult the \u003cspan\u003ersync\u003c/span\u003e manual page for details on specifying the remote directory, e.g.,\u003c/p\u003e\n\u003cpre\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive /opt/PostgreSQL/12 \\\n      /opt/PostgreSQL/18 standby.example.com:/opt/PostgreSQL\n\u003c/pre\u003e\n\u003cp\u003eYou can verify what the command will do using \u003cspan\u003ersync\u003c/span\u003e\u0026#39;s \u003ccode\u003e--dry-run\u003c/code\u003e option. While \u003cspan\u003ersync\u003c/span\u003e must be run on the primary for at least one standby, it is possible to run \u003cspan\u003ersync\u003c/span\u003e on an upgraded standby to upgrade other standbys, as long as the upgraded standby has not been started.\u003c/p\u003e\n\u003cp\u003eWhat this does is to record the links created by \u003cspan\u003epg_upgrade\u003c/span\u003e\u0026#39;s link mode that connect files in the old and new clusters on the primary server. It then finds matching files in the standby\u0026#39;s old cluster and creates links for them in the standby\u0026#39;s new cluster. Files that were not linked on the primary are copied from the primary to the standby. (They are usually small.) This provides rapid standby upgrades. Unfortunately, \u003cspan\u003ersync\u003c/span\u003e needlessly copies files associated with temporary and unlogged tables because these files don\u0026#39;t normally exist on standby servers.\u003c/p\u003e\n\u003cp\u003eIf you have tablespaces, you will need to run a similar \u003cspan\u003ersync\u003c/span\u003e command for each tablespace directory, e.g.:\u003c/p\u003e\n\u003cpre\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive /vol1/pg_tblsp/PG_12_201909212 \\\n      /vol1/pg_tblsp/PG_18_202307071 standby.example.com:/vol1/pg_tblsp\n\u003c/pre\u003e\n\u003cp\u003eIf you have relocated \u003ccode\u003epg_wal\u003c/code\u003e outside the data directories, \u003cspan\u003ersync\u003c/span\u003e must be run on those directories too.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eConfigure streaming replication and log-shipping standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eConfigure the servers for log shipping. (You do not need to run \u003ccode\u003epg_backup_start()\u003c/code\u003e and \u003ccode\u003epg_backup_stop()\u003c/code\u003e or take a file system backup as the standbys are still synchronized with the primary.) If the old primary is prior to version 17.0, then no slots on the primary are copied to the new standby, so all the slots on the old standby must be recreated manually. If the old primary is version 17.0 or later, then only logical slots on the primary are copied to the new standby, but other slots on the old standby are not copied, so must be recreated manually.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eRestore \u003ccode\u003epg_hba.conf\u003c/code\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you modified \u003ccode\u003epg_hba.conf\u003c/code\u003e, restore its original settings. It might also be necessary to adjust other configuration files in the new cluster to match the old cluster, e.g., \u003ccode\u003epostgresql.conf\u003c/code\u003e (and any files included by it), \u003ccode\u003epostgresql.auto.conf\u003c/code\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eStart the new server\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe new server can now be safely started, and then any \u003cspan\u003ersync\u003c/span\u003e\u0026#39;ed standby servers.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003ePost-upgrade processing\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf any post-upgrade processing is required, pg_upgrade will issue warnings as it completes. It will also generate script files that must be run by the administrator. The script files will connect to each database that needs post-upgrade processing. Each script should be run using:\u003c/p\u003e\n\u003cpre\u003epsql --username=postgres --file=script.sql postgres\n\u003c/pre\u003e\n\u003cp\u003eThe scripts can be run in any order and can be deleted once they have been run.\u003c/p\u003e\n\u003cdiv\u003e\n\u003ch3\u003eCaution\u003c/h3\u003e\n\u003cp\u003eIn general it is unsafe to access tables referenced in rebuild scripts until the rebuild scripts have run to completion; doing so could yield incorrect results or poor performance. Tables not referenced in rebuild scripts can be accessed immediately.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eStatistics\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eUnless the \u003ccode\u003e--no-statistics\u003c/code\u003e option is specified, \u003ccode\u003epg_upgrade\u003c/code\u003e will transfer most optimizer statistics from the old cluster to the new cluster. This does not transfer all statistics, such as those created explicitly with \u003ca href=\"/docs/18/sql-createstatistics.html\" title=\"CREATE STATISTICS\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE STATISTICS\u003c/span\u003e\u003c/a\u003e, custom statistics added by an extension, or statistics collected by the cumulative statistics system.\u003c/p\u003e\n\u003cp\u003eBecause not all statistics are transferred by \u003ccode\u003epg_upgrade\u003c/code\u003e, you will be instructed to run commands to regenerate that information at the end of the upgrade. You might need to set connection parameters to match your new cluster.\u003c/p\u003e\n\u003cp\u003eFirst, use \u003ccode\u003evacuumdb --all --analyze-in-stages --missing-stats-only\u003c/code\u003e to quickly generate minimal optimizer statistics for relations without any. Then, use \u003ccode\u003evacuumdb --all --analyze-only\u003c/code\u003e to ensure all relations have updated cumulative statistics for triggering vacuum and analyze. For both commands, the use of \u003ccode\u003e--jobs\u003c/code\u003e can speed it up. If \u003ccode\u003evacuum_cost_delay\u003c/code\u003e is set to a non-zero value, this can be overridden to speed up statistics generation using \u003ccode\u003ePGOPTIONS\u003c/code\u003e, e.g., \u003ccode\u003ePGOPTIONS=\u0026#39;-c vacuum_cost_delay=0\u0026#39; vacuumdb ...\u003c/code\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eDelete old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eOnce you are satisfied with the upgrade, you can delete the old cluster\u0026#39;s data directories by running the script mentioned when \u003ccode\u003epg_upgrade\u003c/code\u003e completes. (Automatic deletion is not possible if you have user-defined tablespaces inside the old data directory.) You can also delete the old installation directories (e.g., \u003ccode\u003ebin\u003c/code\u003e, \u003ccode\u003eshare\u003c/code\u003e).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"PGUPGRADE-STEP-REVERT\"\u003e\n\u003cp\u003e\u003cstrong\u003eReverting to old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf, after running \u003ccode\u003epg_upgrade\u003c/code\u003e, you wish to revert to the old cluster, there are several options:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003eIf the \u003ccode\u003e--check\u003c/code\u003e option was used, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf neither \u003ccode\u003e--link\u003c/code\u003e nor \u003ccode\u003e--swap\u003c/code\u003e was used, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf the \u003ccode\u003e--link\u003c/code\u003e option was used, the data files might be shared between the old and new cluster:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003eIf \u003ccode\u003epg_upgrade\u003c/code\u003e aborted before linking started, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf you did \u003cspan\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e start the new cluster, the old cluster was unmodified except that, when linking started, a \u003ccode\u003e.old\u003c/code\u003e suffix was appended to \u003ccode\u003e$PGDATA/global/pg_control\u003c/code\u003e. To reuse the old cluster, remove the \u003ccode\u003e.old\u003c/code\u003e suffix from \u003ccode\u003e$PGDATA/global/pg_control\u003c/code\u003e; you can then restart the old cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf you did start the new cluster, it has written to shared files and it is unsafe to use the old cluster. The old cluster will need to be restored from backup in this case.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf the \u003ccode\u003e--swap\u003c/code\u003e option was used, the old cluster might be destructively modified:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003eIf \u003ccode\u003epg_upgrade\u003c/code\u003e aborts before reporting that the old cluster is no longer safe to start, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eIf \u003ccode\u003epg_upgrade\u003c/code\u003e has reported that the old cluster is no longer safe to start, the old cluster was destructively modified. The old cluster will need to be restored from backup in this case.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.13.8\"\u003e\n\u003ch2\u003eEnvironment\u003c/h2\u003e\n\u003cp\u003eSome environment variables can be used to provide defaults for command-line options:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePGBINOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old PostgreSQL executable directory; option \u003ccode\u003e-b\u003c/code\u003e/\u003ccode\u003e--old-bindir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePGBINNEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new PostgreSQL executable directory; option \u003ccode\u003e-B\u003c/code\u003e/\u003ccode\u003e--new-bindir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePGDATAOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old database cluster configuration directory; option \u003ccode\u003e-d\u003c/code\u003e/\u003ccode\u003e--old-datadir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePGDATANEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new database cluster configuration directory; option \u003ccode\u003e-D\u003c/code\u003e/\u003ccode\u003e--new-datadir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePGPORTOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old cluster port number; option \u003ccode\u003e-p\u003c/code\u003e/\u003ccode\u003e--old-port\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePGPORTNEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new cluster port number; option \u003ccode\u003e-P\u003c/code\u003e/\u003ccode\u003e--new-port\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePGSOCKETDIR\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDirectory to use for postmaster sockets during upgrade; option \u003ccode\u003e-s\u003c/code\u003e/\u003ccode\u003e--socketdir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePGUSER\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCluster\u0026#39;s install user name; option \u003ccode\u003e-U\u003c/code\u003e/\u003ccode\u003e--username\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.13.9\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003epg_upgrade\u003c/span\u003e creates various working files, such as schema dumps, stored within \u003ccode\u003epg_upgrade_output.d\u003c/code\u003e in the directory of the new cluster. Each run creates a new subdirectory named with a timestamp formatted as per ISO 8601 (\u003ccode\u003e%Y%m%dT%H%M%S\u003c/code\u003e), where all its generated files are stored. \u003ccode\u003epg_upgrade_output.d\u003c/code\u003e and its contained files will be removed automatically if \u003cspan\u003epg_upgrade\u003c/span\u003e completes successfully; but in the event of trouble, the files there may provide useful debugging information.\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003epg_upgrade\u003c/span\u003e launches short-lived postmasters in the old and new data directories. Temporary Unix socket files for communication with these postmasters are, by default, made in the current working directory. In some situations the path name for the current directory might be too long to be a valid socket name. In that case you can use the \u003ccode\u003e-s\u003c/code\u003e option to put the socket files in some directory with a shorter path name. For security, be sure that that directory is not readable or writable by any other users. (This is not supported on Windows.)\u003c/p\u003e\n\u003cp\u003eAll failure, rebuild, and reindex cases will be reported by \u003cspan\u003epg_upgrade\u003c/span\u003e if they affect your installation; post-upgrade scripts to rebuild tables and indexes will be generated automatically. If you are trying to automate the upgrade of many clusters, you should find that clusters with identical database schemas require the same post-upgrade steps for all cluster upgrades; this is because the post-upgrade steps are based on the database schemas, and not user data.\u003c/p\u003e\n\u003cp\u003eFor deployment testing, create a schema-only copy of the old cluster, insert dummy data, and upgrade that.\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003epg_upgrade\u003c/span\u003e does not support upgrading of databases containing table columns using these \u003ccode\u003ereg*\u003c/code\u003e OID-referencing system data types:\u003c/p\u003e\n\u003ctable\u003e\n\u003ctbody\u003e\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eregcollation\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eregconfig\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eregdictionary\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eregnamespace\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eregoper\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eregoperator\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eregproc\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eregprocedure\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\u003c/table\u003e\n\u003cp\u003e(\u003ccode\u003eregclass\u003c/code\u003e, \u003ccode\u003eregrole\u003c/code\u003e, and \u003ccode\u003eregtype\u003c/code\u003e can be upgraded.)\u003c/p\u003e\n\u003cp\u003eIf you want to use link mode and you do not want your old cluster to be modified when the new cluster is started, consider using the clone mode. If that is not available, make a copy of the old cluster and upgrade that in link mode. To make a valid copy of the old cluster, use \u003ccode\u003ersync\u003c/code\u003e to create a dirty copy of the old cluster while the server is running, then shut down the old server and run \u003ccode\u003ersync --checksum\u003c/code\u003e again to update the copy with any changes to make it consistent. (\u003ccode\u003e--checksum\u003c/code\u003e is necessary because \u003ccode\u003ersync\u003c/code\u003e only has file modification-time granularity of one second.) You might want to exclude some files, e.g., \u003ccode\u003epostmaster.pid\u003c/code\u003e, as documented in \u003ca href=\"/docs/18/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" rel=\"nofollow\"\u003eSection 25.3.4\u003c/a\u003e. If your file system supports file system snapshots or copy-on-write file copies, you can use that to make a backup of the old cluster and tablespaces, though the snapshot and copies must be created simultaneously or while the database server is down.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.13.10\"\u003e\n\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/docs/18/app-initdb.html\" title=\"initdb\" rel=\"nofollow\"\u003e\u003cspan\u003e\u003cspan\u003einitdb\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/docs/18/app-pg-ctl.html\" title=\"pg_ctl\" rel=\"nofollow\"\u003e\u003cspan\u003e\u003cspan\u003epg_ctl\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/docs/18/app-pgdump.html\" title=\"pg_dump\" rel=\"nofollow\"\u003e\u003cspan\u003e\u003cspan\u003epg_dump\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/docs/18/app-postgres.html\" title=\"postgres\" rel=\"nofollow\"\u003e\u003cspan\u003e\u003cspan\u003epostgres\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","ContentHash":"4ac0c8b7288e9bc7891f36350d3a74d366a86c79072d6c6af09d3e29f9d72d34","Payload":{"description":["pg_upgrade — upgrade a PostgreSQL server instance"],"manual_html":"\u003cdiv\u003e\u003cdiv class=\"refentry\" id=\"PGUPGRADE\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\u003c/div\u003e\n\u003cdiv class=\"refnamediv\"\u003e\n\u003ch2\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_upgrade — upgrade a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server instance\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsynopsisdiv\"\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv class=\"cmdsynopsis\"\u003e\n\u003cp id=\"id-1.9.5.13.4.1\"\u003e\u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e \u003ccode class=\"option\"\u003e-b\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldbindir\u003c/code\u003e\u003c/em\u003e [\u003ccode class=\"option\"\u003e-B\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003enewbindir\u003c/code\u003e\u003c/em\u003e] \u003ccode class=\"option\"\u003e-d\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldconfigdir\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"option\"\u003e-D\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003enewconfigdir\u003c/code\u003e\u003c/em\u003e [\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...]\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e (formerly called \u003cspan class=\"application\"\u003epg_migrator\u003c/span\u003e) allows data stored in \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e data files to be upgraded to a later \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e major version without the data dump/restore typically required for major version upgrades, e.g., from 12.14 to 13.10 or from 14.9 to 15.5. It is not required for minor version upgrades, e.g., from 12.7 to 12.8 or from 14.1 to 14.5.\u003c/p\u003e\n\u003cp\u003eMajor PostgreSQL releases regularly add new features that often change the layout of the system tables, but the internal data storage format rarely changes. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e uses this fact to perform rapid upgrades by creating new system tables and simply reusing the old user data files. If a future major release ever changes the data storage format in a way that makes the old data format unreadable, \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e will not be usable for such upgrades. (The community will attempt to avoid such situations.)\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e does its best to make sure the old and new clusters are binary-compatible, e.g., by checking for compatible compile-time settings, including 32/64-bit binaries. It is important that any external modules are also binary compatible, though this cannot be checked by \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e supports upgrades from 9.2.X and later to the current major release of \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e, including snapshot and beta releases.\u003c/p\u003e\n\u003cdiv class=\"warning\"\u003e\n\u003ch3 class=\"title\"\u003eWarning\u003c/h3\u003e\n\u003cp\u003eUpgrading a cluster causes the destination to execute arbitrary code of the source superusers' choice. Ensure that the source superusers are trusted before upgrading.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-b\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--old-bindir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old PostgreSQL executable directory; environment variable \u003ccode class=\"envar\"\u003ePGBINOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-B\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--new-bindir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ebindir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new PostgreSQL executable directory; default is the directory where \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e resides; environment variable \u003ccode class=\"envar\"\u003ePGBINNEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-c\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--check\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003echeck clusters only, don't change any data\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-d\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--old-datadir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old database cluster configuration directory; environment variable \u003ccode class=\"envar\"\u003ePGDATAOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-D\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--new-datadir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003econfigdir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new database cluster configuration directory; environment variable \u003ccode class=\"envar\"\u003ePGDATANEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-j \u003cem class=\"replaceable\"\u003e\u003ccode\u003enjobs\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--jobs=\u003cem class=\"replaceable\"\u003e\u003ccode\u003enjobs\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003enumber of simultaneous connections and processes/threads to use\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-k\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--link\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003euse hard links instead of copying files to the new cluster\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-N\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--no-sync\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eBy default, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will wait for all files of the upgraded cluster to be written safely to disk. This option causes \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-o\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--old-options\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eoptions to be passed directly to the old \u003ccode class=\"command\"\u003epostgres\u003c/code\u003e command; multiple option invocations are appended\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-O\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--new-options\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoptions\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eoptions to be passed directly to the new \u003ccode class=\"command\"\u003epostgres\u003c/code\u003e command; multiple option invocations are appended\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-p\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--old-port=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe old cluster port number; environment variable \u003ccode class=\"envar\"\u003ePGPORTOLD\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-P\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--new-port=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eport\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ethe new cluster port number; environment variable \u003ccode class=\"envar\"\u003ePGPORTNEW\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-r\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--retain\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eretain SQL and log files even after successful completion\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-s\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--socketdir=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003edir\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003edirectory to use for postmaster sockets during upgrade; default is current working directory; environment variable \u003ccode class=\"envar\"\u003ePGSOCKETDIR\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-U\u003c/code\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--username=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eusername\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ecluster's install user name; environment variable \u003ccode class=\"envar\"\u003ePGUSER\u003c/code\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-v\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--verbose\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eenable verbose internal logging\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003edisplay version information, then exit\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--clone\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse efficient file cloning (also known as \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003ereflinks\u003c/span\u003e”\u003c/span\u003e on some systems) instead of copying files to the new cluster. This can result in near-instantaneous copying of the data files, giving the speed advantages of \u003ccode class=\"option\"\u003e-k\u003c/code\u003e/\u003ccode class=\"option\"\u003e--link\u003c/code\u003e while leaving the old cluster untouched.\u003c/p\u003e\n\u003cp\u003eFile cloning is only supported on some operating systems and file systems. If it is selected but not supported, the \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e run will error. At present, it is supported on Linux (kernel 4.5 or later) with Btrfs and XFS (on file systems created with reflink support), and on macOS with APFS.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--copy\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCopy files to the new cluster. This is the default. (See also \u003ccode class=\"option\"\u003e--link\u003c/code\u003e, \u003ccode class=\"option\"\u003e--clone\u003c/code\u003e, \u003ccode class=\"option\"\u003e--copy-file-range\u003c/code\u003e, and \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e.)\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--copy-file-range\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eUse the \u003ccode class=\"function\"\u003ecopy_file_range\u003c/code\u003e system call for efficient copying. On some file systems this gives results similar to \u003ccode class=\"option\"\u003e--clone\u003c/code\u003e, sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path. At present, it is supported on Linux and FreeBSD.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--no-statistics\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDo not restore statistics from the old cluster into the new cluster.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--set-char-signedness=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eManually set the default char signedness of new clusters. Possible values are \u003ccode class=\"literal\"\u003esigned\u003c/code\u003e and \u003ccode class=\"literal\"\u003eunsigned\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eIn the C language, the default signedness of the \u003ccode class=\"type\"\u003echar\u003c/code\u003e type (when not explicitly specified) varies across platforms. For example, \u003ccode class=\"type\"\u003echar\u003c/code\u003e defaults to \u003ccode class=\"type\"\u003esigned char\u003c/code\u003e on x86 CPUs but to \u003ccode class=\"type\"\u003eunsigned char\u003c/code\u003e on ARM CPUs.\u003c/p\u003e\n\u003cp\u003eStarting from \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 18, database clusters maintain their own default char signedness setting, which can be used to ensure consistent behavior across platforms with different default char signedness. By default, \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e preserves the char signedness setting when upgrading from an existing cluster. However, when upgrading from \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 17 or earlier, \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e adopts the char signedness of the platform on which it was built.\u003c/p\u003e\n\u003cp\u003eThis option allows you to explicitly set the default char signedness for the new cluster, overriding any inherited values. There are two specific scenarios where this option is relevant:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf you are planning to migrate to a different platform after the upgrade, you should not use this option. The default behavior is right in this case. Instead, perform the upgrade on the original platform without this flag, and then migrate the cluster afterward. This is the recommended and safest approach.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf you have already migrated the cluster to a platform with different char signedness (for example, from an x86-based system to an ARM-based system), you should use this option to specify the signedness matching the original platform's default char signedness. Additionally, it's essential not to modify any data files between migrating data files and running \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e. \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e should be the first operation that starts the cluster on the new platform.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--swap\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eMove the data directories from the old cluster to the new cluster. Then, replace the catalog files with those generated for the new cluster. This mode can outperform \u003ccode class=\"option\"\u003e--link\u003c/code\u003e, \u003ccode class=\"option\"\u003e--clone\u003c/code\u003e, \u003ccode class=\"option\"\u003e--copy\u003c/code\u003e, and \u003ccode class=\"option\"\u003e--copy-file-range\u003c/code\u003e, especially on clusters with many relations.\u003c/p\u003e\n\u003cp\u003eHowever, this mode creates many garbage files in the old cluster, which can prolong the file synchronization step if \u003ccode class=\"option\"\u003e--sync-method=syncfs\u003c/code\u003e is used. Therefore, it is recommended to use \u003ccode class=\"option\"\u003e--sync-method=fsync\u003c/code\u003e with \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eAdditionally, once the file transfer step begins, the old cluster will be destructively modified and therefore will no longer be safe to start. See \u003ca class=\"xref\" href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REVERT\" title=\"Reverting to old cluster\"\u003eStep 17\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--sync-method=\u003c/code\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003emethod\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWhen set to \u003ccode class=\"literal\"\u003efsync\u003c/code\u003e, which is the default, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will recursively open and synchronize all files in the upgraded cluster's data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace.\u003c/p\u003e\n\u003cp\u003eOn Linux, \u003ccode class=\"literal\"\u003esyncfs\u003c/code\u003e may be used instead to ask the operating system to synchronize the whole file systems that contain the upgraded cluster's data directory, its WAL files, and each tablespace. See \u003ca class=\"xref\" href=\"/docs/18/runtime-config-error-handling.html#GUC-RECOVERY-INIT-SYNC-METHOD\"\u003erecovery_init_sync_method\u003c/a\u003e for information about the caveats to be aware of when using \u003ccode class=\"literal\"\u003esyncfs\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThis option has no effect when \u003ccode class=\"option\"\u003e--no-sync\u003c/code\u003e is used.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eshow help, then exit\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.7\"\u003e\n\u003ch2\u003eUsage\u003c/h2\u003e\n\u003cp\u003eThese are the steps to perform an upgrade with \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e:\u003c/p\u003e\n\u003cdiv class=\"note\"\u003e\n\u003ch3 class=\"title\"\u003eNote\u003c/h3\u003e\n\u003cp\u003eThe steps to upgrade \u003ca class=\"glossterm\" href=\"/docs/18/glossary.html#GLOSSARY-LOGICAL-REPLICATION-CLUSTER\"\u003e\u003c/a\u003e\u003ca class=\"glossterm\" href=\"/docs/18/glossary.html#GLOSSARY-LOGICAL-REPLICATION-CLUSTER\" title=\"Logical replication cluster\"\u003elogical replication clusters\u003c/a\u003e are not covered here; refer to \u003ca class=\"xref\" href=\"/docs/18/logical-replication-upgrade.html\" title=\"29.13. Upgrade\"\u003eSection 29.13\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"procedure\"\u003e\n\u003col class=\"procedure\"\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eOptionally move the old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you are using a version-specific installation directory, e.g., \u003ccode class=\"filename\"\u003e/opt/PostgreSQL/18\u003c/code\u003e, you do not need to move the old cluster. The graphical installers all use version-specific installation directories.\u003c/p\u003e\n\u003cp\u003eIf your installation directory is not version-specific, e.g., \u003ccode class=\"filename\"\u003e/usr/local/pgsql\u003c/code\u003e, it is necessary to move the current PostgreSQL install directory so it does not interfere with the new \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e installation. Once the current \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server is shut down, it is safe to rename the PostgreSQL installation directory; assuming the old directory is \u003ccode class=\"filename\"\u003e/usr/local/pgsql\u003c/code\u003e, you can do:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003emv /usr/local/pgsql /usr/local/pgsql.old\n\u003c/pre\u003e\n\u003cp\u003eto rename the directory.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eFor source installs, build the new version\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eBuild the new PostgreSQL source with \u003ccode class=\"command\"\u003econfigure\u003c/code\u003e flags that are compatible with the old cluster. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e will check \u003ccode class=\"command\"\u003epg_controldata\u003c/code\u003e to make sure all settings are compatible before starting the upgrade.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInstall the new PostgreSQL binaries\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInstall the new server's binaries and support files. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e is included in a default installation.\u003c/p\u003e\n\u003cp\u003eFor source installs, if you wish to install the new server in a custom location, use the \u003ccode class=\"literal\"\u003eprefix\u003c/code\u003e variable:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003emake prefix=/usr/local/pgsql.new install\n\u003c/pre\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInitialize the new PostgreSQL cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInitialize the new cluster using \u003ccode class=\"command\"\u003einitdb\u003c/code\u003e. Again, use compatible \u003ccode class=\"command\"\u003einitdb\u003c/code\u003e flags that match the old cluster. Many prebuilt installers do this step automatically. There is no need to start the new cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInstall extension shared object files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMany extensions and custom modules, whether from \u003ccode class=\"filename\"\u003econtrib\u003c/code\u003e or another source, use shared object files (or DLLs), e.g., \u003ccode class=\"filename\"\u003epgcrypto.so\u003c/code\u003e. If the old cluster used these, shared object files matching the new server binary must be installed in the new cluster, usually via operating system commands. Do not load the schema definitions, e.g., \u003ccode class=\"command\"\u003eCREATE EXTENSION pgcrypto\u003c/code\u003e, because these will be duplicated from the old cluster. If extension updates are available, \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e will report this and create a script that can be run later to update them.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eCopy custom full-text search files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eCopy any custom full text search files (dictionary, synonym, thesaurus, stop words) from the old to the new cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eAdjust authentication\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will connect to the old and new servers several times, so you might want to set authentication to \u003ccode class=\"literal\"\u003epeer\u003c/code\u003e in \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e or use a \u003ccode class=\"filename\"\u003e~/.pgpass\u003c/code\u003e file (see \u003ca class=\"xref\" href=\"/docs/18/libpq-pgpass.html\" title=\"32.16. The Password File\"\u003eSection 32.16\u003c/a\u003e).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eStop both servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure both database servers are stopped using, on Unix, e.g.:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epg_ctl -D /opt/PostgreSQL/12 stop\npg_ctl -D /opt/PostgreSQL/18 stop\n\u003c/pre\u003e\n\u003cp\u003eor on Windows, using the proper service names:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eNET STOP postgresql-12\nNET STOP postgresql-18\n\u003c/pre\u003e\n\u003cp\u003eStreaming replication and log-shipping standby servers must be running during this shutdown so they receive all changes.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003ePrepare for standby server upgrades\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you are upgrading standby servers using methods outlined in section \u003ca class=\"xref\" href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REPLICAS\" title=\"Upgrade streaming replication and log-shipping standby servers\"\u003eStep 11\u003c/a\u003e, verify that the old standby servers are caught up by running \u003cspan class=\"application\"\u003epg_controldata\u003c/span\u003e against the old primary and standby clusters. Verify that the \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eLatest checkpoint location\u003c/span\u003e”\u003c/span\u003e values match in all clusters. Also, make sure \u003ccode class=\"varname\"\u003ewal_level\u003c/code\u003e is not set to \u003ccode class=\"literal\"\u003eminimal\u003c/code\u003e in the \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e file on the new primary cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eRun \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eAlways run the \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e binary of the new server, not the old one. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e requires the specification of the old and new cluster's data and executable (\u003ccode class=\"filename\"\u003ebin\u003c/code\u003e) directories. You can also specify user and port values, and whether you want the data files linked, cloned, or swapped instead of the default copy behavior.\u003c/p\u003e\n\u003cp\u003eIf you use link mode, the upgrade will be much faster (no file copying) and use less disk space, but you will not be able to access your old cluster once you start the new cluster after the upgrade. Link mode also requires that the old and new cluster data directories be in the same file system. (Tablespaces and \u003ccode class=\"filename\"\u003epg_wal\u003c/code\u003e can be on different file systems.) Clone mode provides the same speed and disk space advantages but does not cause the old cluster to be unusable once the new cluster is started. Clone mode also requires that the old and new data directories be in the same file system. This mode is only available on certain operating systems and file systems. Swap mode may be the fastest if there are many relations, but you will not be able to access your old cluster once the file transfer step begins. Swap mode also requires that the old and new cluster data directories be in the same file system.\u003c/p\u003e\n\u003cp\u003eSetting \u003ccode class=\"option\"\u003e--jobs\u003c/code\u003e to 2 or higher allows pg_upgrade to process multiple databases and tablespaces in parallel. A good starting point is the number of CPU cores on the machine. This option can substantially reduce the upgrade time for multi-database and multi-tablespace servers.\u003c/p\u003e\n\u003cp\u003eFor Windows users, you must be logged into an administrative account, and then run \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e with quoted directories, e.g.:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epg_upgrade.exe\n        --old-datadir \"C:/Program Files/PostgreSQL/12/data\"\n        --new-datadir \"C:/Program Files/PostgreSQL/18/data\"\n        --old-bindir \"C:/Program Files/PostgreSQL/12/bin\"\n        --new-bindir \"C:/Program Files/PostgreSQL/18/bin\"\n\u003c/pre\u003e\n\u003cp\u003eOnce started, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will verify the two clusters are compatible and then do the upgrade. You can use \u003ccode class=\"command\"\u003epg_upgrade --check\u003c/code\u003e to perform only the checks, even if the old server is still running. \u003ccode class=\"command\"\u003epg_upgrade --check\u003c/code\u003e will also outline any manual adjustments you will need to make after the upgrade. If you are going to be using link, clone, copy-file-range, or swap mode, you should use the option \u003ccode class=\"option\"\u003e--link\u003c/code\u003e, \u003ccode class=\"option\"\u003e--clone\u003c/code\u003e, \u003ccode class=\"option\"\u003e--copy-file-range\u003c/code\u003e, or \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e with \u003ccode class=\"option\"\u003e--check\u003c/code\u003e to enable mode-specific checks. \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e requires write permission in the current directory.\u003c/p\u003e\n\u003cp\u003eObviously, no one should be accessing the clusters during the upgrade. \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e defaults to running servers on port 50432 to avoid unintended client connections. You can use the same port number for both clusters when doing an upgrade because the old and new clusters will not be running at the same time. However, when checking an old running server, the old and new port numbers must be different.\u003c/p\u003e\n\u003cp\u003eIf an error occurs while restoring the database schema, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will exit and you will have to revert to the old cluster as outlined in \u003ca class=\"xref\" href=\"/docs/18/pgupgrade.html#PGUPGRADE-STEP-REVERT\" title=\"Reverting to old cluster\"\u003eStep 17\u003c/a\u003e below. To try \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e again, you will need to modify the old cluster so the pg_upgrade schema restore succeeds. If the problem is a \u003ccode class=\"filename\"\u003econtrib\u003c/code\u003e module, you might need to uninstall the \u003ccode class=\"filename\"\u003econtrib\u003c/code\u003e module from the old cluster and install it in the new cluster after the upgrade, assuming the module is not being used to store user data.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\" id=\"PGUPGRADE-STEP-REPLICAS\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eUpgrade streaming replication and log-shipping standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you used link mode and have Streaming Replication (see \u003ca class=\"xref\" href=\"/docs/18/warm-standby.html#STREAMING-REPLICATION\" title=\"26.2.5. Streaming Replication\"\u003eSection 26.2.5\u003c/a\u003e) or Log-Shipping (see \u003ca class=\"xref\" href=\"/docs/18/warm-standby.html\" title=\"26.2. Log-Shipping Standby Servers\"\u003eSection 26.2\u003c/a\u003e) standby servers, you can follow these steps to quickly upgrade them. You will not be running \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e on the standby servers, but rather \u003cspan class=\"application\"\u003ersync\u003c/span\u003e on the primary. Do not start any servers yet.\u003c/p\u003e\n\u003cp\u003eIf you did \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e use link mode, do not have or do not want to use \u003cspan class=\"application\"\u003ersync\u003c/span\u003e, or want an easier solution, skip the instructions in this section and simply recreate the standby servers once \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e completes and the new primary is running.\u003c/p\u003e\n\u003cdiv class=\"procedure\"\u003e\n\u003col class=\"procedure\"\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInstall the new PostgreSQL binaries on standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure the new binaries and support files are installed on all standby servers.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eMake sure the new standby data directories do \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e exist\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eMake sure the new standby data directories do \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e exist or are empty. If \u003cspan class=\"application\"\u003einitdb\u003c/span\u003e was run, delete the standby servers' new data directories.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eInstall extension shared object files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eInstall the same extension shared object files on the new standbys that you installed in the new primary cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eStop standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf the standby servers are still running, stop them now using the above instructions.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eSave configuration files\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eSave any configuration files from the old standbys' configuration directories you need to keep, e.g., \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e (and any files included by it), \u003ccode class=\"filename\"\u003epostgresql.auto.conf\u003c/code\u003e, \u003ccode class=\"literal\"\u003epg_hba.conf\u003c/code\u003e, because these will be overwritten or removed in the next step.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eRun \u003cspan class=\"application\"\u003ersync\u003c/span\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eWhen using link mode, standby servers can be quickly upgraded using \u003cspan class=\"application\"\u003ersync\u003c/span\u003e. To accomplish this, from a directory on the primary server that is above the old and new database cluster directories, run this on the \u003cspan class=\"emphasis\"\u003e\u003cem\u003eprimary\u003c/em\u003e\u003c/span\u003e for each standby server:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive old_cluster new_cluster remote_dir\n\u003c/pre\u003e\n\u003cp\u003ewhere \u003ccode class=\"option\"\u003eold_cluster\u003c/code\u003e and \u003ccode class=\"option\"\u003enew_cluster\u003c/code\u003e are relative to the current directory on the primary, and \u003ccode class=\"option\"\u003eremote_dir\u003c/code\u003e is \u003cspan class=\"emphasis\"\u003e\u003cem\u003eabove\u003c/em\u003e\u003c/span\u003e the old and new cluster directories on the standby. The directory structure under the specified directories on the primary and standbys must match. Consult the \u003cspan class=\"application\"\u003ersync\u003c/span\u003e manual page for details on specifying the remote directory, e.g.,\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive /opt/PostgreSQL/12 \\\n      /opt/PostgreSQL/18 standby.example.com:/opt/PostgreSQL\n\u003c/pre\u003e\n\u003cp\u003eYou can verify what the command will do using \u003cspan class=\"application\"\u003ersync\u003c/span\u003e's \u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e option. While \u003cspan class=\"application\"\u003ersync\u003c/span\u003e must be run on the primary for at least one standby, it is possible to run \u003cspan class=\"application\"\u003ersync\u003c/span\u003e on an upgraded standby to upgrade other standbys, as long as the upgraded standby has not been started.\u003c/p\u003e\n\u003cp\u003eWhat this does is to record the links created by \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e's link mode that connect files in the old and new clusters on the primary server. It then finds matching files in the standby's old cluster and creates links for them in the standby's new cluster. Files that were not linked on the primary are copied from the primary to the standby. (They are usually small.) This provides rapid standby upgrades. Unfortunately, \u003cspan class=\"application\"\u003ersync\u003c/span\u003e needlessly copies files associated with temporary and unlogged tables because these files don't normally exist on standby servers.\u003c/p\u003e\n\u003cp\u003eIf you have tablespaces, you will need to run a similar \u003cspan class=\"application\"\u003ersync\u003c/span\u003e command for each tablespace directory, e.g.:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003ersync --archive --delete --hard-links --size-only --no-inc-recursive /vol1/pg_tblsp/PG_12_201909212 \\\n      /vol1/pg_tblsp/PG_18_202307071 standby.example.com:/vol1/pg_tblsp\n\u003c/pre\u003e\n\u003cp\u003eIf you have relocated \u003ccode class=\"filename\"\u003epg_wal\u003c/code\u003e outside the data directories, \u003cspan class=\"application\"\u003ersync\u003c/span\u003e must be run on those directories too.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eConfigure streaming replication and log-shipping standby servers\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eConfigure the servers for log shipping. (You do not need to run \u003ccode class=\"function\"\u003epg_backup_start()\u003c/code\u003e and \u003ccode class=\"function\"\u003epg_backup_stop()\u003c/code\u003e or take a file system backup as the standbys are still synchronized with the primary.) If the old primary is prior to version 17.0, then no slots on the primary are copied to the new standby, so all the slots on the old standby must be recreated manually. If the old primary is version 17.0 or later, then only logical slots on the primary are copied to the new standby, but other slots on the old standby are not copied, so must be recreated manually.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eRestore \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf you modified \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e, restore its original settings. It might also be necessary to adjust other configuration files in the new cluster to match the old cluster, e.g., \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e (and any files included by it), \u003ccode class=\"filename\"\u003epostgresql.auto.conf\u003c/code\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eStart the new server\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe new server can now be safely started, and then any \u003cspan class=\"application\"\u003ersync\u003c/span\u003e'ed standby servers.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003ePost-upgrade processing\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf any post-upgrade processing is required, pg_upgrade will issue warnings as it completes. It will also generate script files that must be run by the administrator. The script files will connect to each database that needs post-upgrade processing. Each script should be run using:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epsql --username=postgres --file=script.sql postgres\n\u003c/pre\u003e\n\u003cp\u003eThe scripts can be run in any order and can be deleted once they have been run.\u003c/p\u003e\n\u003cdiv class=\"caution\"\u003e\n\u003ch3 class=\"title\"\u003eCaution\u003c/h3\u003e\n\u003cp\u003eIn general it is unsafe to access tables referenced in rebuild scripts until the rebuild scripts have run to completion; doing so could yield incorrect results or poor performance. Tables not referenced in rebuild scripts can be accessed immediately.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eStatistics\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eUnless the \u003ccode class=\"option\"\u003e--no-statistics\u003c/code\u003e option is specified, \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e will transfer most optimizer statistics from the old cluster to the new cluster. This does not transfer all statistics, such as those created explicitly with \u003ca class=\"xref\" href=\"/docs/18/sql-createstatistics.html\" title=\"CREATE STATISTICS\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE STATISTICS\u003c/span\u003e\u003c/a\u003e, custom statistics added by an extension, or statistics collected by the cumulative statistics system.\u003c/p\u003e\n\u003cp\u003eBecause not all statistics are transferred by \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e, you will be instructed to run commands to regenerate that information at the end of the upgrade. You might need to set connection parameters to match your new cluster.\u003c/p\u003e\n\u003cp\u003eFirst, use \u003ccode class=\"command\"\u003evacuumdb --all --analyze-in-stages --missing-stats-only\u003c/code\u003e to quickly generate minimal optimizer statistics for relations without any. Then, use \u003ccode class=\"command\"\u003evacuumdb --all --analyze-only\u003c/code\u003e to ensure all relations have updated cumulative statistics for triggering vacuum and analyze. For both commands, the use of \u003ccode class=\"option\"\u003e--jobs\u003c/code\u003e can speed it up. If \u003ccode class=\"varname\"\u003evacuum_cost_delay\u003c/code\u003e is set to a non-zero value, this can be overridden to speed up statistics generation using \u003ccode class=\"envar\"\u003ePGOPTIONS\u003c/code\u003e, e.g., \u003ccode class=\"literal\"\u003ePGOPTIONS='-c vacuum_cost_delay=0' vacuumdb ...\u003c/code\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eDelete old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eOnce you are satisfied with the upgrade, you can delete the old cluster's data directories by running the script mentioned when \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e completes. (Automatic deletion is not possible if you have user-defined tablespaces inside the old data directory.) You can also delete the old installation directories (e.g., \u003ccode class=\"filename\"\u003ebin\u003c/code\u003e, \u003ccode class=\"filename\"\u003eshare\u003c/code\u003e).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"step\" id=\"PGUPGRADE-STEP-REVERT\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eReverting to old cluster\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIf, after running \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e, you wish to revert to the old cluster, there are several options:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf the \u003ccode class=\"option\"\u003e--check\u003c/code\u003e option was used, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf neither \u003ccode class=\"option\"\u003e--link\u003c/code\u003e nor \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e was used, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf the \u003ccode class=\"option\"\u003e--link\u003c/code\u003e option was used, the data files might be shared between the old and new cluster:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e aborted before linking started, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf you did \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e start the new cluster, the old cluster was unmodified except that, when linking started, a \u003ccode class=\"literal\"\u003e.old\u003c/code\u003e suffix was appended to \u003ccode class=\"filename\"\u003e$PGDATA/global/pg_control\u003c/code\u003e. To reuse the old cluster, remove the \u003ccode class=\"filename\"\u003e.old\u003c/code\u003e suffix from \u003ccode class=\"filename\"\u003e$PGDATA/global/pg_control\u003c/code\u003e; you can then restart the old cluster.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf you did start the new cluster, it has written to shared files and it is unsafe to use the old cluster. The old cluster will need to be restored from backup in this case.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf the \u003ccode class=\"option\"\u003e--swap\u003c/code\u003e option was used, the old cluster might be destructively modified:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e aborts before reporting that the old cluster is no longer safe to start, the old cluster was unmodified; it can be restarted.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eIf \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e has reported that the old cluster is no longer safe to start, the old cluster was destructively modified. The old cluster will need to be restored from backup in this case.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.8\"\u003e\n\u003ch2\u003eEnvironment\u003c/h2\u003e\n\u003cp\u003eSome environment variables can be used to provide defaults for command-line options:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGBINOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old PostgreSQL executable directory; option \u003ccode class=\"option\"\u003e-b\u003c/code\u003e/\u003ccode class=\"option\"\u003e--old-bindir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGBINNEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new PostgreSQL executable directory; option \u003ccode class=\"option\"\u003e-B\u003c/code\u003e/\u003ccode class=\"option\"\u003e--new-bindir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGDATAOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old database cluster configuration directory; option \u003ccode class=\"option\"\u003e-d\u003c/code\u003e/\u003ccode class=\"option\"\u003e--old-datadir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGDATANEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new database cluster configuration directory; option \u003ccode class=\"option\"\u003e-D\u003c/code\u003e/\u003ccode class=\"option\"\u003e--new-datadir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGPORTOLD\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe old cluster port number; option \u003ccode class=\"option\"\u003e-p\u003c/code\u003e/\u003ccode class=\"option\"\u003e--old-port\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGPORTNEW\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe new cluster port number; option \u003ccode class=\"option\"\u003e-P\u003c/code\u003e/\u003ccode class=\"option\"\u003e--new-port\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGSOCKETDIR\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eDirectory to use for postmaster sockets during upgrade; option \u003ccode class=\"option\"\u003e-s\u003c/code\u003e/\u003ccode class=\"option\"\u003e--socketdir\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"envar\"\u003ePGUSER\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eCluster's install user name; option \u003ccode class=\"option\"\u003e-U\u003c/code\u003e/\u003ccode class=\"option\"\u003e--username\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.9\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e creates various working files, such as schema dumps, stored within \u003ccode class=\"filename\"\u003epg_upgrade_output.d\u003c/code\u003e in the directory of the new cluster. Each run creates a new subdirectory named with a timestamp formatted as per ISO 8601 (\u003ccode class=\"literal\"\u003e%Y%m%dT%H%M%S\u003c/code\u003e), where all its generated files are stored. \u003ccode class=\"filename\"\u003epg_upgrade_output.d\u003c/code\u003e and its contained files will be removed automatically if \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e completes successfully; but in the event of trouble, the files there may provide useful debugging information.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e launches short-lived postmasters in the old and new data directories. Temporary Unix socket files for communication with these postmasters are, by default, made in the current working directory. In some situations the path name for the current directory might be too long to be a valid socket name. In that case you can use the \u003ccode class=\"option\"\u003e-s\u003c/code\u003e option to put the socket files in some directory with a shorter path name. For security, be sure that that directory is not readable or writable by any other users. (This is not supported on Windows.)\u003c/p\u003e\n\u003cp\u003eAll failure, rebuild, and reindex cases will be reported by \u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e if they affect your installation; post-upgrade scripts to rebuild tables and indexes will be generated automatically. If you are trying to automate the upgrade of many clusters, you should find that clusters with identical database schemas require the same post-upgrade steps for all cluster upgrades; this is because the post-upgrade steps are based on the database schemas, and not user data.\u003c/p\u003e\n\u003cp\u003eFor deployment testing, create a schema-only copy of the old cluster, insert dummy data, and upgrade that.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_upgrade\u003c/span\u003e does not support upgrading of databases containing table columns using these \u003ccode class=\"type\"\u003ereg*\u003c/code\u003e OID-referencing system data types:\u003c/p\u003e\n\u003ctable class=\"simplelist\"\u003e\n\u003ctbody\u003e\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregcollation\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregconfig\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregdictionary\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregnamespace\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregoper\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregoperator\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregproc\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eregprocedure\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\u003c/table\u003e\n\u003cp\u003e(\u003ccode class=\"type\"\u003eregclass\u003c/code\u003e, \u003ccode class=\"type\"\u003eregrole\u003c/code\u003e, and \u003ccode class=\"type\"\u003eregtype\u003c/code\u003e can be upgraded.)\u003c/p\u003e\n\u003cp\u003eIf you want to use link mode and you do not want your old cluster to be modified when the new cluster is started, consider using the clone mode. If that is not available, make a copy of the old cluster and upgrade that in link mode. To make a valid copy of the old cluster, use \u003ccode class=\"command\"\u003ersync\u003c/code\u003e to create a dirty copy of the old cluster while the server is running, then shut down the old server and run \u003ccode class=\"command\"\u003ersync --checksum\u003c/code\u003e again to update the copy with any changes to make it consistent. (\u003ccode class=\"option\"\u003e--checksum\u003c/code\u003e is necessary because \u003ccode class=\"command\"\u003ersync\u003c/code\u003e only has file modification-time granularity of one second.) You might want to exclude some files, e.g., \u003ccode class=\"filename\"\u003epostmaster.pid\u003c/code\u003e, as documented in \u003ca class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.4. Making a Base Backup Using the Low Level API\"\u003eSection 25.3.4\u003c/a\u003e. If your file system supports file system snapshots or copy-on-write file copies, you can use that to make a backup of the old cluster and tablespaces, though the snapshot and copies must be created simultaneously or while the database server is down.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.13.10\"\u003e\n\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/docs/18/app-initdb.html\" title=\"initdb\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003einitdb\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/docs/18/app-pg-ctl.html\" title=\"pg_ctl\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_ctl\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/docs/18/app-pgdump.html\" title=\"pg_dump\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_dump\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/docs/18/app-postgres.html\" title=\"postgres\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epostgres\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","related":[],"sections":[],"tables":[{"columns":[{"key":"signature","label":"Option and arguments"},{"key":"summary","label":"Description"}],"key":"options","rows":[{"signature":{"text":"-b bindir --old-bindir= bindir","url":"/docs/18/pgupgrade.html"},"summary":"the old PostgreSQL executable directory; environment variable PGBINOLD"},{"signature":{"text":"-B bindir --new-bindir= bindir","url":"/docs/18/pgupgrade.html"},"summary":"the new PostgreSQL executable directory; default is the directory where pg_upgrade resides; environment variable PGBINNEW"},{"signature":{"text":"-c --check","url":"/docs/18/pgupgrade.html"},"summary":"check clusters only, don't change any data"},{"signature":{"text":"-d configdir --old-datadir= configdir","url":"/docs/18/pgupgrade.html"},"summary":"the old database cluster configuration directory; environment variable PGDATAOLD"},{"signature":{"text":"-D configdir --new-datadir= configdir","url":"/docs/18/pgupgrade.html"},"summary":"the new database cluster configuration directory; environment variable PGDATANEW"},{"signature":{"text":"-j njobs --jobs= njobs","url":"/docs/18/pgupgrade.html"},"summary":"number of simultaneous connections and processes/threads to use"},{"signature":{"text":"-k --link","url":"/docs/18/pgupgrade.html"},"summary":"use hard links instead of copying files to the new cluster"},{"signature":{"text":"-N --no-sync","url":"/docs/18/pgupgrade.html"},"summary":"By default, pg_upgrade will wait for all files of the upgraded cluster to be written safely to disk. This option causes pg_upgrade to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing but should not be used on a production installation."},{"signature":{"text":"-o options --old-options options","url":"/docs/18/pgupgrade.html"},"summary":"options to be passed directly to the old postgres command; multiple option invocations are appended"},{"signature":{"text":"-O options --new-options options","url":"/docs/18/pgupgrade.html"},"summary":"options to be passed directly to the new postgres command; multiple option invocations are appended"},{"signature":{"text":"-p port --old-port= port","url":"/docs/18/pgupgrade.html"},"summary":"the old cluster port number; environment variable PGPORTOLD"},{"signature":{"text":"-P port --new-port= port","url":"/docs/18/pgupgrade.html"},"summary":"the new cluster port number; environment variable PGPORTNEW"},{"signature":{"text":"-r --retain","url":"/docs/18/pgupgrade.html"},"summary":"retain SQL and log files even after successful completion"},{"signature":{"text":"-s dir --socketdir= dir","url":"/docs/18/pgupgrade.html"},"summary":"directory to use for postmaster sockets during upgrade; default is current working directory; environment variable PGSOCKETDIR"},{"signature":{"text":"-U username --username= username","url":"/docs/18/pgupgrade.html"},"summary":"cluster's install user name; environment variable PGUSER"},{"signature":{"text":"-v --verbose","url":"/docs/18/pgupgrade.html"},"summary":"enable verbose internal logging"},{"signature":{"text":"-V --version","url":"/docs/18/pgupgrade.html"},"summary":"display version information, then exit"},{"signature":{"text":"--clone","url":"/docs/18/pgupgrade.html"},"summary":"Use efficient file cloning (also known as “ reflinks ” on some systems) instead of copying files to the new cluster. This can result in near-instantaneous copying of the data files, giving the speed advantages of -k / --link while leaving the old cluster untouched."},{"signature":{"text":"--copy","url":"/docs/18/pgupgrade.html"},"summary":"Copy files to the new cluster. This is the default. (See also --link , --clone , --copy-file-range , and --swap .)"},{"signature":{"text":"--copy-file-range","url":"/docs/18/pgupgrade.html"},"summary":"Use the copy_file_range system call for efficient copying. On some file systems this gives results similar to --clone , sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path. At present, it is supported on Linux and FreeBSD."},{"signature":{"text":"--no-statistics","url":"/docs/18/pgupgrade.html"},"summary":"Do not restore statistics from the old cluster into the new cluster."},{"signature":{"text":"--set-char-signedness= option","url":"/docs/18/pgupgrade.html"},"summary":"Manually set the default char signedness of new clusters. Possible values are signed and unsigned ."},{"signature":{"text":"--swap","url":"/docs/18/pgupgrade.html"},"summary":"Move the data directories from the old cluster to the new cluster. Then, 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."},{"signature":{"text":"--sync-method= method","url":"/docs/18/pgupgrade.html"},"summary":"When set to fsync , which is the default, pg_upgrade will recursively open and synchronize all files in the upgraded cluster's data directory. The search for files will follow symbolic links for the WAL directory and each configured tablespace."},{"signature":{"text":"-? --help","url":"/docs/18/pgupgrade.html"},"summary":"show help, then exit"}],"title":"Documented options"},{"columns":[{"key":"name","label":"Variable"},{"key":"description","label":"Meaning"}],"key":"environment","rows":[{"description":"The old PostgreSQL executable directory; option -b / --old-bindir .","name":"PGBINOLD"},{"description":"The new PostgreSQL executable directory; option -B / --new-bindir .","name":"PGBINNEW"},{"description":"The old database cluster configuration directory; option -d / --old-datadir .","name":"PGDATAOLD"},{"description":"The new database cluster configuration directory; option -D / --new-datadir .","name":"PGDATANEW"},{"description":"The old cluster port number; option -p / --old-port .","name":"PGPORTOLD"},{"description":"The new cluster port number; option -P / --new-port .","name":"PGPORTNEW"},{"description":"Directory to use for postmaster sockets during upgrade; option -s / --socketdir .","name":"PGSOCKETDIR"},{"description":"Cluster's install user name; option -U / --username .","name":"PGUSER"}],"title":"Environment variables"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
