| PG_UPGRADECLUSTER(1) | Debian PostgreSQL infrastructure | PG_UPGRADECLUSTER(1) |
pg_upgradecluster - upgrade an existing PostgreSQL cluster to a new major version.
pg_upgradecluster [-v newversion] oldversion name [newdatadir]
pg_upgradecluster upgrades an existing PostgreSQL server cluster (i. e. a collection of databases served by a postgres instance) to a new version specified by newversion (default: latest available version). The configuration files of the old version are copied to the new cluster and adjusted for the new version.
By default, pg_dump(1) is used to migrate data and indexes to the new cluster. This is slow, but safe. Upgrade variants based on pg_upgrade(1) can be selected using the --method=upgrade parameter. This is faster, but care must be taken when using it in the context of an operating system upgrade. The sorting order ("collation") used in indexes is determined by libc and libicu, and new versions of these libraries might have a differ ordering, requiring index rebuilds after the upgrade, or acknowledging that the ordering did not change using the ALTER COLLATION REFRESH VERSION command. This step is not automated by pg_upgradecluster.
The cluster of the old version will be configured to use a previously unused port since the upgraded one will use the original port. The old cluster is not automatically removed. After upgrading, please verify that the new cluster indeed works as expected; if so, you should remove the old cluster with pg_dropcluster(8). Please note that the old cluster is set to "manual" startup mode, in order to avoid inadvertently changing it; this means that it will not be started automatically on system boot, and you have to use pg_ctlcluster(8) to start/stop it. See section "STARTUP CONTROL" in pg_createcluster(8) for details.
The newdatadir argument can be used to specify a non-default data directory of the upgraded cluster. It is passed to pg_createcluster. If not specified, this defaults to /var/lib/postgresql/newversion/name.
When upgrading to PostgreSQL 11 or newer, this option no longer allows switching the encoding of individual databases. (pg_dumpall(1) was changed to retain database encodings.)
link and clone are shorthands for -m upgrade --link and -m upgrade --clone, respectively.
The --method=dump behavior can explictly be controlled by the --data-checksums and --no-data-checksums options.
Some PostgreSQL extensions like PostGIS need metadata in auxiliary tables which must not be upgraded from the old version, but rather initialized for the new version before copying the table data. For this purpose, extensions (as well as administrators, of course) can drop upgrade hook scripts into /etc/postgresql-common/pg_upgradecluster.d/. Script file names must consist entirely of upper and lower case letters, digits, underscores, and hyphens; in particular, dots (i. e. file extensions) are not allowed.
Scripts in that directory will be called with the following arguments:
<old version> <cluster name> <new version> <phase>
Phases:
Failing scripts will abort the upgrade. The scripts are called as the user who owns the database.
pg_createcluster(8), pg_dropcluster(8), pg_lsclusters(1), pg_wrapper(1), pg_dump(1), pg_upgrade(1)
Martin Pitt <mpitt@debian.org>, Christoph Berg <myon@debian.org>
| 2025-05-07 | Debian |