Skip to content

How to Upgrade your Singlenode PostgreSQL Server

NOC Tower isn't an instrument for upgrading your databases. First it's very complicated process with many pitfalls. Second we don't know your environment. So, you must upgrade Postgres by your own.

Here is a small manual.

Prepare for upgrading database

  1. Stop noc service
  2. systemctl stop noc
  3. Do a backup of PostgreSQL Database
  4. sudo -u postgres pg_dumpall -c -f /tmp/pg_dumpall.out -v -U postgres
  5. save backup file somewhere: cp /tmp/pg_dumpall.out ~/

Upgrade database

Let assume that we want to upgrade from 9.6 to 14 version.

RPM-based distros (Centos, RHEL, Oracle Linux)

  1. Install postgresql-server of new version:
  2. yum install postgresql14-server.x86_64
  3. Init new database from new binary:
  4. /usr/pgsql-14/bin/postgresql-14-setup initdb
  5. Stop old server:
  6. systemctl stop postgresql-9.6
  7. Become postgres user
  8. su - postgres
  9. Check if we can upgrade this database:
  10. /usr/pgsql-14/bin/pg_upgrade --old-bindir=/usr/pgsql-9.6/bin/ --new-bindir=/usr/pgsql-14/bin/ --old-datadir=/var/lib/pgsql/9.6/data/ --new-datadir=/var/lib/pgsql/14/data/ --check

Output example:

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 tables WITH OIDS                               ok
Checking for invalid "sql_identifier" user columns          ok
Checking for invalid "unknown" user columns                 ok
Checking for hash indexes                                   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. Upgrade this database: - /usr/pgsql-14/bin/pg_upgrade --old-bindir=/usr/pgsql-9.6/bin/ --new-bindir=/usr/pgsql-14/bin/ --old-datadir=/var/lib/pgsql/9.6/data/ --new-datadir=/var/lib/pgsql/14/data/

Output example:

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 tables WITH OIDS                               ok
Checking for invalid "sql_identifier" user columns          ok
Checking for invalid "unknown" user columns                 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_clog 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 analyze new cluster                      ok
Creating script to delete old cluster                       ok
Checking for hash indexes                                   ok
Checking for extension updates                              ok

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
    ./analyze_new_cluster.sh

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh
  1. Start new server:
  2. systemctl start postgresql-14
  3. systemctl status postgresql-14

  4. Remove old PG packages:

  5. yum remove postgresql96* -y

  6. Write proper new version of PostgreSQL (14) in the Tower in postgres service at PostgreSQL version field.

  7. Deploy

DEB-based distros (Debian, Ubuntu)

  1. todo!