LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

pg_upgrade

upgrades PostgreSQL to a new major version in place

TLDR

Upgrade cluster
$ pg_upgrade -b [old_bindir] -B [new_bindir] -d [old_datadir] -D [new_datadir]
copy
Check compatibility without upgrading
$ pg_upgrade --check -b [old_bindir] -B [new_bindir] -d [old_datadir] -D [new_datadir]
copy
Upgrade with hard links for speed
$ pg_upgrade --link -b [old_bindir] -B [new_bindir] -d [old_datadir] -D [new_datadir]
copy
Upgrade with file cloning (reflinks, near-instant)
$ pg_upgrade --clone -b [old_bindir] -B [new_bindir] -d [old_datadir] -D [new_datadir]
copy
Upgrade using parallel jobs
$ pg_upgrade -j [4] -b [old_bindir] -B [new_bindir] -d [old_datadir] -D [new_datadir]
copy

SYNOPSIS

pg_upgrade [options]

DESCRIPTION

pg_upgrade upgrades PostgreSQL to a new major version in place. Faster than dump/restore for large databases. Preserves data files when possible. Always run with --check first to verify compatibility before performing the actual upgrade.

PARAMETERS

-b, --old-bindir dir

Old PostgreSQL executable directory.
-B, --new-bindir dir
New PostgreSQL executable directory. Defaults to the directory where pg_upgrade resides.
-d, --old-datadir dir
Old database cluster configuration directory.
-D, --new-datadir dir
New database cluster configuration directory.
-c, --check
Check clusters only, don't change any data.
-k, --link
Use hard links instead of copying files to the new cluster.
--clone
Use efficient file cloning (reflinks) instead of copying. Near-instant on supported filesystems (Btrfs, XFS, macOS APFS).
--copy
Copy files to the new cluster. This is the default.
-j, --jobs njobs
Number of simultaneous processes for copying/linking files and dumping/restoring schemas in parallel.
-p, --old-port port
The old cluster port number.
-P, --new-port port
The new cluster port number.
-U, --username name
Cluster's install user name.
-r, --retain
Retain SQL and log files even after successful completion.
-s, --socketdir dir
Directory for postmaster sockets during upgrade. Default is current working directory.
-N, --no-sync
Do not wait for files to be written safely to disk.
-v, --verbose
Enable verbose internal logging.
-o, --old-options options
Options passed directly to the old postgres command.
-O, --new-options options
Options passed directly to the new postgres command.

INSTALL

sudo dnf install postgresql17
copy
sudo apk add postgresql17
copy
sudo zypper install postgresql17
copy

SEE ALSO

Copied to clipboard
Kai