Stefans Computer Blog


PostgreSQL-Server: Upgrade von Version 10 auf 14 mit pg_upgrade unter OmniOS

In dieser Anleitung beschreibe ich, wie ich heute ein Upgrade meines PostgreSQL-Servers von Version 10 auf 14 mit pg_upgrade unter OmniOS vorgenommen habe.

1. Datensicherung des PostgreSQL 10 Datenbankclusters vornehmen.

2. PostgreSQL-Version 14 installieren.


pkg install database/postgresql-14
			

3. Den neuen PostgreSQL-Datenbankcluster initialisieren


su - postgres

initdb -E unicode -D /var/opt/ooce/pgsql/pgsql-14
			


4. postgresql.conf aus dem Verzeichnis /var/opt/ooce/pgsql/pgsql-10 ins Verzeichnis /var/opt/ooce/pgsql/pgsql-14 kopieren


cd /var/opt/ooce/pgsql/pgsql-14
cp /var/opt/ooce/pgsql/pgsql-10/postgresql.conf .   
			

In der pg_hba.conf in den Verzeichnissen pgsql-10 und pgsql-14 die Authentifizierungsmethode von local auf trust setzen, um pg_upgrade ohne Passworteingabe laufen zu lassen.


# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
			

Anschließend mit exit den User postgres ausloggen.

5. PostgreSQL-Service beider Versionen stoppen


svcadm disable postgresql-14:default
svcadm disable postgresql-10:default
			

6. Zertifikatdateien aus dem Verzeichnis pgsql-10 in das Verzeichnis pgsql-14 kopieren, sofern SSL verwendet wird


cp /var/opt/ooce/pgsql/pgsql-10/server.* /var/opt/ooce/pgsql/pgsql-14 
			

7. pg_upgrade starten

Mit der Option -c wird zunächst ein Check durchgeführt, ob pg_upgrade fehlerfrei durchlaufen kann. Sofern der Check fehlerfrei durchläuft kann im nächsten Schritt die Option -c (am Ende der Befehlszeile) weggelassen werden.


su - postgres

/opt/ooce/pgsql-14/bin/pg_upgrade -b /opt/ooce/pgsql-10/bin -B /opt/ooce/pgsql-14/bin -d /var/opt/ooce/pgsql/pgsql-10 -D /var/opt/ooce/pgsql/pgsql-14  -o '-c config_file=/var/opt/ooce/pgsql/pgsql-10/postgresql.conf' -O '-c config_file=/var/opt/ooce/pgsql/pgsql-14/postgresql.conf'  -c
			

Bei mir kam dann das folgende Ergebnis raus:


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
Checking for incompatible polymorphic functions             ok
Checking for tables WITH OIDS                               fatal

Your installation contains tables declared WITH OIDS, which is not
supported anymore.  Consider removing the oid column using
    ALTER TABLE ... SET WITHOUT OIDS;
A list of tables with the problem is in the file:
    tables_with_oids.txt

Failure, exiting
			

In der Datei 'tables_with_oids.txt' konnte ich dann erkennen, das die Software 'PgAccess' (ein GUI für die Verwaltung von PostgreSQL-Datenbanken), heimlich Tabellen mit OIDS in meine Datenbanken geschrieben hat. PgAccess schreibt die folgenden Tabellen in jede aufgerufene Datenbank:


public.pga_images
public.pga_queries
public.pga_reports
public.pga_forms
public.pga_diagrams
public.pga_graphs
public.pga_layout
public.pga_scripts
			

Das Programm 'PgAccess' habe ich umgehend von meinem Rechner entfernt. Um pg_upgrade auszuführen musste ich also erstmal in allen mit 'PgAccess' geöffneten Datenbanken die o.a. Tabellen löschen.

Wenn der Check mit pg_upgrade ohne Fehler durchgelaufen ist, pg_upgrade ohne Option -c starten.

Das Ergebnis sollte dann wie folgt aussehen:


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
Checking for incompatible polymorphic functions             ok
Checking for tables WITH OIDS                               ok
Checking for invalid "sql_identifier" 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_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                              ok

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
    /opt/ooce/pgsql-14/bin/vacuumdb --all --analyze-in-stages

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh
		    

8. Die pg_hba.conf aus dem Verzeichnis pgsql-10 in das Verzeichnis pgsql-14 kopieren und die ursprüngliche Authentifizierungsmethode für local wieder herstellen.

9. Den PostgreSQL 14 Service starten


svcadm enable postgresql14:default
			 


Kontakt: mail@tkfibu.de


HOME