Smooth Transition: Upgrading PostgreSQL from 11 to 14 for Jira on Redhat family

Hey-hey,

a few guys from Atlassian Telegram community wrote me to post that cookbook into online community, so

Let’s upgrade PostgreSQL from 11 to 14 on Oracle Linux 8 using YUM/RPM.

0. Here you can find RedHat family 8 RPM

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  1. Install the PostgreSQL 14 Packages
$ systemctl stop postgresql-11
$ yum install postgresql14-server.x86_64 postgresql14.x86_64 postgresql14-contrib.x86_64

2. Initialise PostgreSQL 14 database

$ /usr/pgsql-14/bin/postgresql-14-setup initdb

3. Start PostgreSQL 11 database (required for pre-upgrade check)

$ /usr/pgsql-11/bin/pg_ctl -D /var/lib/pgsql/11/data/ start

Or you can skip if it’s still running on

$ systemctl status postgresql

4. Switch into postgres user

$ su postgres

5. Run pre-upgrade check:

$ /usr/pgsql-14/bin/pg_upgrade \
--old-bindir=/usr/pgsql-11/bin \
--new-bindir=/usr/pgsql-14/bin \
--old-datadir=/var/lib/pgsql/11/data \
--new-datadir=/var/lib/pgsql/14/data \
--user=postgres \
--check

“--check” means check clusters only, don’t change any data, additional parameter “--verbose” useful for troubleshooting.

Expected result:

Performing Consistency Checks on Old Live Server
- - - - - - - - - - - - - - - - - - - - - - - -
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for removed "abstime" data type in user tables ok
Checking for removed "reltime" data type in user tables ok
Checking for removed "tinterval" data type in user tables ok
Checking for user-defined encoding conversions ok
Checking for user-defined postfix operators ok
Checking for incompatible polymorphic functions ok
Checking for tables WITH OIDS ok
Checking for invalid "sql_identifier" user columns ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
*Clusters are compatible*

6. Shutdown original PostgreSQL 11

$ /usr/pgsql-11/bin/pg_ctl -D /var/lib/pgsql/11/data/ stop

Or

$ systemctl stop postgresql

7. Run the actual upgrade

$ /usr/pgsql-14/bin/pg_upgrade \
--old-bindir=/usr/pgsql-11/bin \
--new-bindir=/usr/pgsql-14/bin \
--old-datadir=/var/lib/pgsql/11/data \
--new-datadir=/var/lib/pgsql/14/data \
--user=postgres

Additional useful parameters are:

-j, — jobs=NUM number of simultaneous processes or threads to use

-k, — link link instead of copying files to new cluster

Performing Consistency Checks
- - - - - - - - - - - - - - -
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for user-defined encoding conversions ok
Checking for user-defined postfix operators ok
Creating dump of global objects ok
Creating dump of database schemas ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.

Performing Upgrade
- - - - - - - - -
Analyzing all rows in the new cluster ok
Freezing all rows in the new cluster ok
Deleting files from new pg_xact ok
Copying old pg_xact to new server ok
Setting oldest XID for new cluster ok
Setting next transaction ID and epoch for new cluster ok
Deleting files from new pg_multixact/offsets ok
Copying old pg_multixact/offsets to new server ok
Deleting files from new pg_multixact/members ok
Copying old pg_multixact/members to new server ok
Setting next multixact ID and offset for new cluster ok
Resetting WAL archives ok
Setting frozenxid and minmxid counters in new cluster ok
Restoring global objects in the new cluster ok
Restoring database schemas in the new cluster ok
Copying user relation files ok
Setting next OID for new cluster ok
Sync data directory to disk ok
Creating script to delete old cluster ok
Checking for extension updates notice
Your installation contains extensions that should be updated
with the ALTER EXTENSION command. The file
update_extensions.sql
when executed by psql by the database superuser will update
these extensions.
Upgrade Complete
- - - - - - - -
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
/usr/pgsql-14/bin/vacuumdb -U postgres - all - analyze-in-stages
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh

8. Start PostgreSQL 14 cluster

$ systemctl start postgresql-14.service
$ systemctl status postgresql-14.service
● postgresql-14.service — PostgreSQL 14 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2024–01–23 14:30:05 +08; 39s ago
Docs: https://www.postgresql.org/docs/14/static/
Process: 62798 ExecStartPre=/usr/pgsql-14/bin/postgresql-14-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 62799 (postmaster)
Tasks: 8 (limit: 48578)
Memory: 17.0M
CGroup: /system.slice/postgresql-14.service
├─62802 /usr/pgsql-14/bin/postmaster -D /var/lib/pgsql/14/data/
├─62803 postgres: logger
├─62804 postgres: checkpointer
├─62805 postgres: background writer
├─62806 postgres: walwriter
├─62807 postgres: autovacuum launcher
├─62808 postgres: stats collector
└─62810 postgres: logical replication launcher

9. Upgrade the extension

$ cat update_extensions.sql
\connect test
ALTER EXTENSION "pageinspect" UPDATE;
$ psql -U postgres
psql (14.0)
Type "help" for help.
postgres=# \i update_extensions.sql
You are now connected to database "jiradb" as user "postgres".
ALTER EXTENSION

10. Update optimiser statistics

$ /usr/pgsql-14/bin/vacuumdb -U postgres — all — analyze-in-stages
vacuumdb: processing database “postgres”: Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "template1": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "jiradb": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "postgres": Generating medium optimizer statistics (768 targets)
vacuumdb: processing database "template1": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "jiradb": Generating medium optimizer statistics (768 targets)
vacuumdb: processing database "postgres": Generating default (full) optimizer statistics
vacuumdb: processing database "template1": Generating default (full) optimizer statistics
vacuumdb: processing database "test": Generating default (full) optimizer statistics

11. Testing the updated RDBMS with DB

10. Clean up

$ yum remove postgresql11-*
$ rm -rf '/var/lib/pgsql/11/data'

That’s it. Have a good upgrades

1 comment

Birger Robrecht March 14, 2024

Superb instructions. I appreciate it. I just want to add that it might require a password reset after the upgrade. As far as I know, there was a change in the way the credentials are stored in Postgres.

ALTER USER atlassian WITH PASSWORD 'password';

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events