PG_UPGRADE(1) PostgreSQL 18.6 Documentation PG_UPGRADE(1) (NAME) pg_upgrade - PostgreSQL (SYNOPSIS) pg_upgrade -b oldbindir [-B newbindir] -d oldconfigdir -D newconfigdir [option...] (DESCRIPTION) pg_upgrade ( pg_migrator ) PostgreSQL / (dump/restore) (major) PostgreSQL 12.14 13.10 14.9 15.5. (minor) 12.7 12.8 14.1 14.5. PostgreSQL . pg_upgrade . pg_upgrade . ( .) pg_upgrade 32/64-bit. pg_upgrade . pg_upgrade 9.2.X PostgreSQL snapshot beta . (superusers) . . (OPTIONS) pg_upgrade : -b bindir --old-bindir=bindir PostgreSQL PGBINOLD -B bindir --new-bindir=bindir PostgreSQL pg_upgrade PGBINNEW -c --check -d configdir --old-datadir=configdir PGDATAOLD -D configdir --new-datadir=configdir PGDATANEW -j njobs --jobs=njobs / (threads) -k --link (hard links) -N --no-sync pg_upgrade . pg_upgrade (crash) . (production) . -o options --old-options options postgres -O options --new-options options postgres -p port --old-port=port (port) PGPORTOLD -P port --new-port=port (port) PGPORTNEW -r --retain SQL (log) -s dir --socketdir=dir postmaster PGSOCKETDIR -U username --username=username PGUSER -v --verbose -V --version --clone ( "reflinks" ) . -k/--link . . pg_upgrade . Linux ( 4.5 ) Btrfs XFS ( reflink ) macOS APFS . --copy . . ( : --link --clone --copy-file-range --swap.) --copy-file-range copy_file_range . --clone . Linux FreeBSD . --no-statistics . --set-char-signedness=option (signedness) char . signed unsigned. C char ( ) . char x86 signed char ARM unsigned char . PostgreSQL 18 char char . pg_upgrade char . PostgreSQL 17 pg_upgrade char . char . : o . . . . o char ( x86 ARM) char . pg_upgrade . pg_upgrade . --swap . . --link --clone --copy --copy-file-range (relations) . --sync-method=syncfs . --swap --sync-method=fsync . . Step 17 . --sync-method=method fsync ( ) pg_upgrade . WAL tablespace . Linux syncfs WAL tablespace . syncfs recovery_init_sync_method . --no-sync . -? --help pg_upgrade : (logical replication clusters) Section 29.13 . 1. : /opt/PostgreSQL/18 . . /usr/local/pgsql PostgreSQL PostgreSQL . PostgreSQL PostgreSQL /usr/local/pgsql : mv /usr/local/pgsql /usr/local/pgsql.old . 2. : PostgreSQL (flags) configure . pg_upgrade pg_controldata . 3. PostgreSQL: . pg_upgrade . prefix : make prefix=/usr/local/pgsql.new install 4. PostgreSQL: initdb . initdb . . . 5. (shared object) : contrib ( DLL) pgcrypto.so . . (schema definitions) CREATE EXTENSION pgcrypto . pg_upgrade . 6. : ( ) . 7. : pg_upgrade pg_hba.conf peer ~/.pgpass ( Section 32.16 ). 8. : Unix : pg_ctl -D /opt/PostgreSQL/12 stop pg_ctl -D /opt/PostgreSQL/18 stop Windows : NET STOP postgresql-12 NET STOP postgresql-18 standby streaming replication log-shipping . 9. standby: standby Step 11 pg_controldata primary standby standby . "Latest checkpoint location" . wal_level postgresql.conf primary minimal . 10. pg_upgrade: pg_upgrade . pg_upgrade (bin) . (copy) (linked) (cloned) (swapped) . link ( ) . link . (Tablespace pg_wal .) clone . clone . . swap relation . swap . --jobs pg_upgrade tablespace . CPU . tablespace . Windows (administrative) pg_upgrade : pg_upgrade.exe --old-datadir "C:/Program Files/PostgreSQL/12/data" --new-datadir "C:/Program Files/PostgreSQL/18/data" --old-bindir "C:/Program Files/PostgreSQL/12/bin" --new-bindir "C:/Program Files/PostgreSQL/18/bin" pg_upgrade . pg_upgrade --check . pg_upgrade --check . link clone copy-file-range swap --link --clone --copy-file-range --swap --check . pg_upgrade . . pg_upgrade 50432 . . . pg_upgrade Step 17 . pg_upgrade pg_upgrade . contrib contrib . 11. standby (streaming replication) (log-shipping): link standby Streaming Replication ( Section 26.2.5 ) Log-Shipping ( Section 26.2 ) . pg_upgrade standby rsync (primary) . . link rsync pg_upgrade primary standby . 1. PostgreSQL standby: standby . 2. standby : standby . initdb standby . 3. (shared object) : standby primary . 4. standby: standby . 5. : standby postgresql.conf ( ) postgresql.auto.conf pg_hba.conf . 6. rsync: link standby rsync . primary primary standby : rsync --archive --delete --hard-links --size-only --no-inc-recursive old_cluster new_cluster remote_dir old_cluster new_cluster primary remote_dir standby . primary standby . (remote) rsync : rsync --archive --delete --hard-links --size-only --no-inc-recursive /opt/PostgreSQL/12 \ /opt/PostgreSQL/18 standby.example.com:/opt/PostgreSQL --dry-run rsync . rsync standby primary standby rsync standby standby . link pg_upgrade primary . standby standby . primary primary standby . ( .) standby . rsync temporary unlogged standby . tablespace rsync tablespace : rsync --archive --delete --hard-links --size-only --no-inc-recursive /vol1/pg_tblsp/PG_12_201909212 \ /vol1/pg_tblsp/PG_18_202307071 standby.example.com:/vol1/pg_tblsp pg_wal rsync . 7. standby streaming replication log-shipping: log shipping . ( pg_backup_start() pg_backup_stop() standby primary .) primary 17.0 slot primary standby slot standby . primary 17.0 slot (logical slots) primary standby slot standby . 12. pg_hba.conf: pg_hba.conf . postgresql.conf ( ) postgresql.auto.conf. 13. : standby rsync . 14. : pg_upgrade . . . : psql --username=postgres --file=script.sql postgres . (rebuild) . . 15. : --no-statistics pg_upgrade . CREATE STATISTICS (CREATE_STATISTICS(7)) . pg_upgrade . . vacuumdb --all --analyze-in-stages --missing-stats-only . vacuumdb --all --analyze-only vacuum analyze . --jobs . vacuum_cost_delay PGOPTIONS : PGOPTIONS='-c vacuum_cost_delay=0' vacuumdb .... 16. : pg_upgrade . ( (tablespaces) .) ( bin share) . 17. : pg_upgrade : o --check . o --link --swap . o --link : o pg_upgrade . o .old $PGDATA/global/pg_control . .old $PGDATA/global/pg_control . o . . o --swap : o pg_upgrade . o pg_upgrade . . : PGBINOLD PostgreSQL -b/--old-bindir. PGBINNEW PostgreSQL -B/--new-bindir. PGDATAOLD -d/--old-datadir. PGDATANEW -D/--new-datadir. PGPORTOLD -p/--old-port. PGPORTNEW -P/--new-port. PGSOCKETDIR postmaster -s/--socketdir. PGUSER -U/--username. (NOTES) pg_upgrade pg_upgrade_output.d . ISO 8601 (%Y%m%dT%H%M%S) . pg_upgrade pg_upgrade_output.d . pg_upgrade postmaster . postmaster . . -s . . ( Windows .) (reindex) pg_upgrade . . . pg_upgrade reg* OID : regcollation regconfig regdictionary regnamespace regoper regoperator regproc regprocedure ( regclass regrole regtype .) (link mode) (clone mode) . . rsync (dirty copy) rsync --checksum . ( --checksum rsync .) postmaster.pid Section 25.3.4 . copy-on-write tablespace ..SH " (SEE ALSO)" initdb(1), pg_ctl(1), pg_dump(1), postgres(1) PostgreSQL 18.6 2026 PG_UPGRADE(1)