SUSE Manager/postgresql96

From MicroFocusInternationalWiki
Jump to: navigation, search

SUSE Manager 3.x with postgresql 9.6 database

SUSE Manager 3 is using postgresql database version 9.4. Meanwhile version 9.6 of postgresql has been officially released for the underlying operating system, so we are soon supporting the new version as well. Right now the version is hardcoded for SUSE Manager, so if you currently install SUMA, it will explicitly be using the old version 9.4. Of course we will also support migration of existing SUSE Manager installations to the new database version.

New installation

As soon as support of postgresql 9.6 is officially released for SUSE Manager, there is nothing special to be done for new installations. It will just pick up the new version and installation is fully transparent to the user. No special steps are needed.

You can check the active postgresql version with the following command:

suma-test-srv:~ # psql --version
psql (PostgreSQL) 9.6.3

Migration of existing installations

Before migrating to the new database version, make sure SUSE Manager is fully patched to the latest version. You can check if the system is ready to use postgresql 9.6 by issuing the following command:

suma-test-srv:~ # rpm -q smdba
smdba-1.5.8-0.2.3.1.x86_64

You need at least version 1.5.8 for being able to use postgresql 9.6 with SUSE Manager.

Of course it is advisable to have a backup of the installation before performing the actual migration. The migration itself is performed by this command:

$> /usr/lib/susemanager/bin/pg-migrate.sh

The script will do the following:

  • stop spacewalk services
  • shut down the database
  • check if postgresql 9.6 is already installed and install it if not already present
  • switch to using the new postgresql 9.6 as default
  • perform the actual database migration
  • create a postgresql configuration tuned for use by SUSE Manager (this is why the new smdba is needed)
  • start database and spacewalk services

Please note that during the migration the data directory of the database is copied for the new version. So temporarily double the disk space is needed. In case the migration fails, the migration script will try to restore the original state. After successful migration, you can delete the old database directory (renamed to /var/lib/pgsql/data-pg94) to reclaim disk space.

Fast migration

The regular migration has two negative aspects: you temporarily need double the disk space under /var/lib/pgsql and depending on the size of the database the migration can take up some time because the whole data directory needs to be copied.

It is however possible to do a so-called fast migration. In this case you do not need the additional disk space as the database files will not be copied but hard linked instead. Besides not needing additional disk space this also will speed up the migration process massively; the whole migration will be done in less than one minute in that case.

Of course restoration in case of failure is not possible in this case. So the fast migration should only be done if a backup is available.

The fast migration will be performed by this command:

$> /usr/lib/susemanager/bin/pg-migrate.sh fast

Sample session

This is how a typical migration should look like:

d235:~ # /usr/lib/susemanager/bin/pg-migrate.sh
15:58:00   Shut down spacewalk services...
Shutting down spacewalk services...
Done.
15:58:03   Checking postgresql version...
15:58:03   Installing postgresql 9.6...
Dienst 'SUSE_Linux_Enterprise_Server_12_SP2_x86_64' wird aktualisiert.
Dienst 'SUSE_Manager_Server_3.1_x86_64' wird aktualisiert.
Repository-Daten werden geladen...
Installierte Pakete werden gelesen...
Paketabhängigkeiten werden aufgelöst...

Die folgenden 3 NEUEN Pakete werden installiert:
  postgresql96 postgresql96-contrib postgresql96-server

3 neue Pakete zu installieren.
Gesamtgröße des Downloads: 5,7 MiB. Bereits im Cache gespeichert: 0 B. Nach der Operation werden zusätzlich 25,3 MiB belegt.
Fortfahren? [j/n/...? zeigt alle Optionen] (j): j
Paket postgresql96-9.6.3-2.4.x86_64 abrufen (1/3),   1,3 MiB (  5,1 MiB entpackt)
Abrufen: postgresql96-9.6.3-2.4.x86_64.rpm [fertig]
Paket postgresql96-server-9.6.3-2.4.x86_64 abrufen (2/3),   3,7 MiB ( 17,9 MiB entpackt)
Abrufen: postgresql96-server-9.6.3-2.4.x86_64.rpm [.fertig]
Paket postgresql96-contrib-9.6.3-2.4.x86_64 abrufen (3/3), 648,9 KiB (  2,2 MiB entpackt)
Abrufen: postgresql96-contrib-9.6.3-2.4.x86_64.rpm [fertig]
Überprüfung auf Dateikonflikte läuft: [......fertig]
(1/3) Installieren: postgresql96-9.6.3-2.4.x86_64 [............fertig]
(2/3) Installieren: postgresql96-server-9.6.3-2.4.x86_64 [............fertig]
(3/3) Installieren: postgresql96-contrib-9.6.3-2.4.x86_64 [............fertig]
15:58:08   Ensure postgresql 9.6 is being used as default...
15:58:09   Successfully switched to new postgresql version 9.6.
15:58:09   Create new database directory...
15:58:09   Initialize new postgresql 9.6 database...
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /var/lib/pgsql/data -l logfile start

15:58:12   Successfully initialized new postgresql 9.6 database.
15:58:12   Upgrade database to new version postgresql 9.6...
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 reg* system OID user data types                ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for roles starting with 'pg_'                      ok
Creating dump of global objects                             ok
Creating dump of database schemas
  postgres
  susemanager
  template1
                                                            ok
Checking for presence of required libraries                 ok
Checking database user is the install user                  ok
Checking for prepared transactions                          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 on the new cluster                        ok
Deleting files from new pg_clog                             ok
Copying old pg_clog to new server                           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
  postgres
  susemanager
  template1
                                                            ok
Copying user relation files
  /var/lib/pgsql/data-pg94/base/12753/12710

[...]

  /var/lib/pgsql/data-pg94/base/1/12574
                                                            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

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
15:58:51   Successfully upgraded database to postgresql 9.6.
15:58:51   Tune new postgresql configuration...
INFO: Database configuration has been changed.
INFO: Wrote new general configuration. Backup as /var/lib/pgsql/data/postgresql.2017-07-26-15-58-51.conf
INFO: Wrote new client auth configuration. Backup as /var/lib/pgsql/data/pg_hba.2017-07-26-15-58-51.conf
INFO: Configuration has been changed, but your database is right now offline.
Database is offline
System check finished
15:58:51   Successfully tuned new postgresql configuration.
15:58:51   Starting spacewalk services...
Starting spacewalk services...
Done.