Upgrade Postgresql Streaming Replication Setup
Upgrade Postgresql Streaming Replication Setup
OS:Redhat Linux
OS Version:9
Primary server:172.31.95.130
Standby server:172.31.42.140
mv /usr/local/pgsql /usr/local/pgsql_old
#If you are using extensions install postgresql16-contrib for extension updates
sudo dnf install -y postgresql16-contrib
Note: Streaming replication and log-shipping standby servers must be running during this
shutdown, so they receive all changes.
Step7)Run pg_upgrade
#Always run the pg_upgrade binary of the new server, not the old one. pg_upgrade requires the
specification of the old and new cluster's data and executable (bin) directories.
#use hard links(option -k) instead of copying files to the new cluster
Make sure the new standby data directories do not exist or are empty. If initdb was run, delete
the standby servers' new data directories.
#Run rsync
When using link mode, standby server can be quickly upgraded using rsync ,run this on the
primary for standby server:
rsync --archive --delete --hard-links --size-only --no-inc-recursive /app/data
/var/lib/pgsql/16/data
#If you have tablespaces, you will need to run a similar rsync command for each
tablespace directory
cd /var/lib/pgsql/16/data
touch standby.signal
#Edit postgresql.conf
vim /var/lib/pgsql/16/data/postgresql.conf
listen_addresses = '*'
port = 5432
hot_standby = on
save&exit
vim /var/lib/pgsql/16/data/postgresql.conf
listen_addresses = '*'
port = 5432
wal_level = replica
archive_mode = on
save&exit
vim /var/lib/pgsql/16/data/pg_hba.conf
# replication privilege.
save&exit
rm -rf '/app/data'
rm -rf '/app/tbl_space1/PG_9.5_201510051'
rm -rf '/app/tbl_space2/PG_9.5_201510051'