Database Migration to Latest Version

This section covers upgrading the PostgreSQL database to the latest version. If you are already using PostgreSQL 14, you do not need to perform this migration.

If you want to upgrade to the latest SUSE Manager version, you must be using PostgreSQL version 13 or 14, depending on the underlying operating system:

  • If you are running SUSE Linux Enterprise Server 15 SP3, use PostgreSQL 13.

  • If you are running SUSE Linux Enterprise Server 15 SP4, use PostgreSQL 14.

1. Prepare to Upgrade

Before you begin the upgrade, prepare your existing SUSE Manager Server and create a database backup.

PostgreSQL stores data at /var/lib/pgsql/data/.

Procedure: Preparing to Upgrade
  1. Check the active PostgreSQL version:

    psql --version
  2. Check the active smdba version:

    rpm -q smdba

    PostgreSQL 14 requires smdba version 1.7.6 or later.

  3. Perform a database backup. For more information on backing up, see Backup and Restore.

2. Upgrade PostgreSQL

Always create a database backup before performing a migration.

PostgreSQL upgrades can be performed in two ways: a regular upgrade, or a fast upgrade:

A regular upgrade creates a complete copy of the database, so you need double the existing database size of space available. Regular upgrades can take a considerable amount of time, depending on the size of the database and the speed of the storage system.

A fast upgrade only takes a few minutes, and uses almost no additional disk space. However, if a fast upgrade fails, you must restore the database from the backup. A fast upgrade reduces the risk of running out of disk space, but increases the risk of data lose when a backup does not exist or cannot be replayed. A regular upgrade will copy the database files instead of creating hard links between the files.

PostgreSQL stores data at /var/lib/pgsql/data/.

Before running the DB upgrade make sure that the PostgreSQL user exists on the system. The /etc/passwd entry should look as follows:

postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
Procedure: Performing a Regular Upgrade
  1. Perform a database backup. For more information on backing up, see Backup and Restore.

  2. Start the upgrade. Run the script:

    /usr/lib/susemanager/bin/pg-migrate-x-to-y.sh
  3. When the upgrade has successfully completed, you can safely delete the old database directory and reclaim lost disk space. The old directory is renamed to /var/lib/pgsql/data-pg12 or /var/lib/pgsql/data-pg10, depending on the version you started from.

The pg-migrate-x-to-y.sh script performs these operations:

  • Stop spacewalk services

  • Shut down the running database

  • Check if the latest PostgreSQL is installed and install it if necessary

  • Switch from previous version of PostgreSQL  to the latest as the new default

  • Initiate the database migration

  • Create a PostgreSQL configuration file tuned for use by SUSE Manager

  • Start the database and spacewalk services

If the upgrade fails, the migration script will attempt to restore the database to its original state.

Procedure: Performing a Fast PostgreSQL Upgrade
  1. Perform a database backup. Without a verified database backup, you must not initiate a fast upgrade. For more information on backing up, see Backup and Restore.

  2. Start the upgrade. Run the script.

    /usr/lib/susemanager/bin/pg-migrate-x-to-y.sh -f
  3. When the upgrade has successfully completed, you can safely delete the old database directory and reclaim lost disk space. The old directory is renamed to /var/lib/pgsql/data-pg12 or /var/lib/pgsql/data-pg10, depending on the version you started from.