Search code examples
postgresqlarchlinuxpostgresql-16

pg_upgrade from Postgresql-15 to Postgresql-16 fails with postgis installed


I'm upgrading from Postgres 15 to 16 on Arch using the default documentation. When I reach the pg_upgrade section:

pg_upgrade -b /opt/pgsql-15/bin -B /usr/bin -d /var/lib/postgres/olddata -D /var/lib/postgres/data

Then I get a "failure" exit. When I check the pg_upgrade_output.d log file I found an error related to PostGIS path:

command: "/usr/bin/pg_dump" --host /var/lib/postgres --port 50432 --username postgres --schema-only --quote-all-identifiers --binary-upgrade --format=custom  --file="/var/lib/postgres/data/pg_upgrade_output.d/20231207T105131.842/dump/pg_upgrade_dump_16385.custom" 'dbname=linuxbox_db' >> "/var/lib/postgres/data/pg_upgrade_output.d/20231207T105131.842/log/pg_upgrade_dump_16385.log" 2>&1
pg_dump: error: query failed: ERROR:  could not access file "$libdir/postgis-3": No such file or directory

Is it something on my system or a bug in the pg_upgrade code?


Solution

  • The error was because I needed to rebuild the postgis library after installing v16 and before running the pg_upgrade.

    If someone else ends up having trouble upgrading on Arch, here is a summary of the steps I followed:

    sudo systemctl stop postgresql.service

    sudo mv /var/lib/postgres/data /var/lib/postgres/olddata

    • create new data directory and assign it to postgres user

    sudo mkdir /var/lib/postgres/data /var/lib/postgres/tmp
    sudo chown postgres:postgres /var/lib/postgres/data /var/lib/postgres/tmp

    • install new version of Postgres including postgresql-old-upgrade
    • get into postgres user and tmp directory

    sudo -i -u postgres
    [postgres]$ cd /var/lib/postgres/tmp

    • initialize new db as

    [postgres]$ initdb -D /var/lib/postgres/data --locale=C.UTF-8 --encoding=UTF8

    • start systmctl service from my user

    sudo systemctl start postgresql.service

    • update h3 from postgres account

    pgxn install h3

    • rebuild libraries from pacman: gdal, postgis, postgis-old-upgrade, pgsql-ogr-fdw
    • stop systmctl service from my user

    sudo systemctl stop postgresql.service

    • run pg_upgrade changing value to old version using the postgres account

    [postgres]$ pg_upgrade -b /opt/pgsql-PG_VERSION/bin -B /usr/bin -d /var/lib/postgres/olddata -D /var/lib/postgres/data

    • check db is fine and remove tmp and olddata directories