Migration of PostgreSQL 11 to PostgreSQL 15

Migration of PostgreSQL 11 to PostgreSQL 15 is carried out using the postgresql-upgrade script.
After running the script:
  1. Installs PostgreSQL 15.

  2. Migrates data from the current cluster.

  3. Uninstalls PostgreSQL 11 if the data migration is successful.

Data migration is performed using the pg_upgrade utility from PostgresPRO, which is included in the script.

Warning

No backup you risk losing data.

System Requirements

Operating system:

  • Ubuntu 18.04 LTS,

  • Ubuntu 20.04 LTS,

  • Ubuntu 22.04 LTS.

Database:

  • PostgreSQL 11 pre-installed.

Note

The script performs migration by reassigning data files, no additional space is required.

Migration conditions

The script will work if the following conditions are met:

Condition

Description

Comment

PostgreSQL 11 Location

Data and configuration files are located in the directory /var/lib/postgresql/11/

If the data is in a different folder, the script will not be able to find it and use it for updating

Database name

The databases have names: ibatyr, postgres, template0, template1

The script does not transfer databases with other names. Edit the script for transferring archive databases. Use internal regulations to transfer databases that are not part of the infrastructure iBatyr Monitor

Custom Cluster

The user cluster is located on the same host as the database

The script will not work if the user cluster is on a separate host. Use other migration methods

Location of archived databases

All archive databases of the cluster have the path /var/lib/ibatyr/archives specified in the parameter location

The script will stop if one or more databases have the path to /var/lib/postgresql/11 specified in the parameter location (1)

Local server settings

The server console locale matches the locale of the PostgreSQL 11 cluster

If there is a discrepancy, change the console locale using the command: dpkg-reconfigure locales

Note

  1. Archived databases are now saved in the var/lib/ibatyr/archives folder due to changes to in the instructions Creating an archive database. The error invalid tablespace location means that you created archive databases using old instructions. For a solution, contact to the article.

Preparation

Archive databases

To transfer the archive database, open the postgresql-upgrade script for editing:

sudo nano /usr/share/ibatyr/bin/postgresql-upgrade

Change the ARCHIVED_DATABASES variable:

  • when transferring one archive database:

ARCHIVED_DATABASES="archive2023"
  • when transferring several archive databases:

ARCHIVED_DATABASES="archive_2021 archive_2022 archive_2023"

Backup

Before running the script, back up the database using the command:

ibatyr backup_db

Warning

Without a backup before migrating, you risk losing data due to update errors.

Running the script

  1. Run the script in the terminal with the command:

sudo ibatyr postgresql upgrade

The script will automatically check the compatibility of the old and new PostgreSQL clusters using the pg_upgrade utility.

  1. After successful verification, the script will ask for confirmation before updating PostgreSQL:

*** WARNING! You are really want to run Postgres upgrade script (type 'yes')?

Enter yes to begin migrating your PostgreSQL 11 cluster to version 15.

Completing the migration

The script will remove PostgreSQL 11 and prompt you to restart iBatyr Monitor with the command:

ibatyr init

The restart time depends on the size of the database.

If you have any questions, please contact to technical support.

Modification date: 10.07.2024