In-place Postgres major version upgrades v5

You can upgrade a PGD Node to a newer major version of Postgres using the command-line utility bdr_pg_upgrade.

bdr_pg_upgrade internally uses the standard pg_upgrade with PGD-specific logic to ensure a smooth upgrade.

Terminology

This terminology is used when describing the upgrade process and components involved:

Old cluster The existing Postgres cluster node to upgrade, the one from which to migrate data.

New cluster The new Postgres cluster that data is migrated to. This cluster node must be one major version ahead of the old cluster.

Precautions

Standard Postgres major version upgrade precautions apply, including the fact both clusters must meet all the requirements for pg_upgrade.

Additionally, don't use bdr_pg_upgrade if other tools are using replication slots and replication origins, only PGD slots and origins are restored after the upgrade.

You must meet several prerequisites for bdr_pg_upgrade:

  • Disconnect applications using the old cluster. You can, for example, redirect them to another node in the cluster.
  • Configure peer authentication for both clusters. bdr_pg_upgrade requires peer authentication.
  • PGD versions on both clusters must be exactly the same and must be version 4.1.0 or later.
  • The new cluster must be in a shutdown state.
  • You must install PGD packages in the new cluster.
  • The new cluster must be already initialized and configured as needed to match the old cluster configuration.
  • Databases, tables, and other objects must not exist in the new cluster.

We also recommend having the old cluster up prior to running bdr_pg_upgrade. The CLI starts the old cluster if it's shut down.

Usage

To upgrade to a newer major version of Postgres, you must first install the new version.

bdr_pg_upgrade command-line

bdr_pg_upgrade passes all parameters to pg_upgrade. Therefore, you can specify any parameters supported by pg_upgrade.

Synopsis

bdr_pg_upgrade [OPTION] ...

Options

In addition to the options for pg_upgrade, you can pass the following parameters to bdr_pg_upgrade:

  • -b, --old-bindir Old cluster bin directory (required).
  • -B, --new-bindir New cluster bin directory (required).
  • -d, --old-datadir Old cluster data directory (required).
  • -D, --new-datadir REQUIRED new cluster data directory (required).
  • --database PGD database name (required).
  • -p, --old-port Old cluster port number.
  • -s, --socketdir Directory to use for postmaster sockets during upgrade.
  • --check Specify to only perform checks and not modify clusters.

Environment variables

You can use these environment variables in place of command line parameters:

  • PGBINOLD Old cluster bin directory.
  • PGBINNEW New cluster bin directory.
  • PGDATAOLD Old cluster data directory.
  • PGDATANEW New cluster data directory.
  • PGPORTOLD Old cluster port number.
  • PGSOCKETDIR Directory to use for postmaster sockets during upgrade.

Example

Given a scenario where:

  • Old cluster bin directory is /usr/lib/postgresql/13/bin.
  • New cluster bin directory is /usr/lib/postgresql/14/bin.
  • Old cluster data directory is /var/lib/postgresql/13/main.
  • New cluster data directory is /var/lib/postgresql/14/main.
  • Database name is bdrdb.

You can use the following command to upgrade the cluster:

bdr_pg_upgrade \
--old-bindir /usr/lib/postgresql/13/bin \
--new-bindir /usr/lib/postgresql/14/bin \
--old-datadir /var/lib/postgresql/13/main \
--new-datadir /var/lib/postgresql/14/main \
--database bdrdb

Steps performed

Steps performed when running bdr_pg_upgrade.

Note

When --check is supplied as an argument to bdr_pg_upgrade, the CLI skips steps that modify the database.

PGD Postgres checks

Steps--check supplied
Collecting pre-upgrade new cluster control datarun
Checking new cluster state is shutdownrun
Checking PGD versionsrun
Starting old cluster (if shutdown)skip
Connecting to old clusterskip
Checking if bdr schema existsskip
Turning DDL replication offskip
Terminating connections to database.skip
Disabling connections to databaseskip
Waiting for all slots to be flushedskip
Disconnecting from old clusterskip
Stopping old clusterskip
Starting old cluster with PGD disabledskip
Connecting to old clusterskip
Collecting replication originsskip
Collecting replication slotsskip
Disconnecting from old clusterskip
Stopping old clusterskip

pg_upgrade steps

Standard pg_upgrade steps are performed.

Note

If supplied, --check is passed to pg_upgrade.

PGD post-upgrade steps

Steps--check supplied
Collecting old cluster control dataskip
Collecting new cluster control dataskip
Advancing LSN of new clusterskip
Starting new cluster with PGD disabledskip
Connecting to new clusterskip
Creating replication origin, repeated for each originskip
Advancing replication origin, repeated for each originskip
Creating replication slot, repeated for each slotskip
Stopping new clusterskip