In-place Postgres Major Version Upgrades v4

Upgrading a BDR Node to a newer major version of Postgres is possible using the command-line utility bdr_pg_upgrade.

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


Various terminology is used in this documentation to describe the upgrade process and components involved.

old cluster - The existing Postgres cluster node to be upgraded, which data will be migrated from.

new cluster - The new Postgres cluster, which data will be migrated to. This cluster node must be one (1) major version ahead of the old cluster.


Standard Postgres major version upgrade precautions apply, including the fact that all the requirements for pg_upgrade must be met by both clusters.

Additionaly, bdr_pg_upgrade should not be used if there are other tools using replication slots and replication origins, only BDR slots and origins will be restored after the upgrade.

There are several prerequisites for bdr_pg_upgrade that have to be met:

  • Applications using the old cluster have been disconnected, it can for example, be redirected to another node in the cluster
  • Peer authentication is configured for both clusters, bdr_pg_upgrade requires peer authentication
  • The same BDR version must be installed on both clusters.
  • The BDR version must be 4.1.0 or above. Version 3.7.22 and later is also supported.
  • The new cluster must be in a shutdown state
  • BDR packages must be installed 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

It is also recommended to have the old cluster up prior to running bdr_pg_upgrade as the CLI will start the old cluster if it is shutdown.


To upgrade to a newer major version of Postgres, the new version must first be installed.

bdr_pg_upgrade command-line

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


bdr_pg_upgrade [OPTION] ...


In addition to the options for pg_upgrade, the following parameters are can be passed 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 - BDR database name (required)
  • -p, --old-port - old cluster port number
  • -s, --socketdir - directory to use for postmaster sockets during upgrade
  • --check- only perform checks, do not modify clusters

Environment Variables

Environment variables can be used 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


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

The following command could be used 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.


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

BDR Postgres Checks

Steps--check supplied
Collecting pre-upgrade new cluster control datarun
Checking new cluster state is shutdownrun
Checking BDR 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
Waiting for all slots to be flushedskip
Disconnecting from old clusterskip
Stopping old clusterskip
Starting old cluster with BDR 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


--check is passed to pg_upgrade if supplied

BDR 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 BDR 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