Recently I’ve performed an update of my Fedora Workstation to the latest release of Fedora, Fedora 24. I’ve used the dnf system-upgrade method as outlined here to do so, which seemed to work flawlessly.

Tonight I wanted to mess around with a small web application I’ve built, which uses PostgreSQL and PostGIS. After I’ve seen some error messages pointing to an issue with the database I’ve noticed that the PostgreSQL Server was down. Humm, why could that be?

# journalctl -xe
Aug 06 21:17:10 thinkpad systemd[1]: Starting PostgreSQL database server...
Aug 06 21:17:10 thinkpad postgresql-check-db-dir[18976]: An old version of the database format was found.
Aug 06 21:17:10 thinkpad postgresql-check-db-dir[18976]: Use 'postgresql-setup --upgrade' to upgrade to version '9.5'
Aug 06 21:17:10 thinkpad postgresql-check-db-dir[18976]: See /usr/share/doc/postgresql/README.rpm-dist for more information.
Aug 06 21:17:10 thinkpad systemd[1]: postgresql.service: Control process exited, code=exited status=1
Aug 06 21:17:10 thinkpad systemd[1]: Failed to start PostgreSQL database server.

Right. The PostgreSQL server has been updated to version 9.5. That advise seems to be straight forward, so let’s do it:

# dnf install postgresql-upgrade
# postgresql-setup --upgrade

Of course it failed, and with a particularly ugly error:

command: "/usr/bin/pg_dump" --host "/var/lib/pgsql" --port 5432 
--username "postgres" --schema-only --quote-all-identifiers 
--binary-upgrade --format=custom  --file="pg_upgrade_dump_247358.custom"
"dbname" >> "pg_upgrade_dump_247358.log" 2>&1
pg_dump: [archiver (db)] query failed: ERROR:  could not access file 
"$libdir/postgis-2.1": No such file or directory

Interestingly, version 2.1 of PostGIS was included in the latest PostGIS Fedora 24 package, so why is it not working? I found a bug that indicates that I am not the only one with this problem, but at the end it didn’t help me solve it.

No such file or directory. Where the heck was it looking? The file is there! Finally I fired up strace:

# strace -f postgresql-setup --upgrade
...
[pid 24890] stat("/usr/lib64/pgsql/postgresql-9.4/lib/postgis-2.1", 
      0x7ffe928413d0) = -1 ENOENT (No such file or directory)
[pid 24890] stat("/usr/lib64/pgsql/postgresql-9.4/lib/postgis-2.1.so", 
      0x7ffe928413d0) = -1 ENOENT (No such file or directory)
[pid 24890] stat("$libdir/postgis-2.1", 0x7ffe928413c0) = -1 ENOENT 
      (No such file or directory)
...

 

I’ve tried to create a link to point to the existing postgis-2.1.so file in /usr/lib65/pgsql, but long story short, it complained that this version didn’t match the version of the original data files.

The solution was to grab the PostGIS package from Fedora 23, extract the RPM, and copy the postgis-2.1.so file from this RPM to /usr/lib64/pgsql/postgresql-9.4/lib. The RPM can be extracted as follows:

# rpm2cpio postgis-2.1.8-2.fc23.x86_64.rpm | cpio -idmv

 

Having done this, the upgrade procedure went further, but still there was a problem, it started to complain about another missing library:

Could not load library "$libdir/rtpostgis-2.1"
ERROR: could not access file "$libdir/rtpostgis-2.1": 
     No such file or directory

In /usr/lib64/pgsql there is a library called rtpostgis-2.2.so. I’ve tried to use the rtpostgis-2.1.so file from the extracted Fedora 23 RPM, but this time it complained that this was built for an older version. Finally I ended up creating a link, which points to the new version:

# pwd
/usr/lib64/pgsql
# ln -s rtpostgis-2.2.so rtpostgis-2.1.so

And that helped! Now the DB upgrade went through, and I was able to start the PostgreSQL server. The only thing left to do is the actual migration of the database to the new PostGIS version on the SQL prompt of my PostGIS DB:

# ALTER EXTENSION postgis UPDATE TO "2.2.1";

Hope it helps some people out there to save some time.

 

3 thoughts on “Upgrading PostGIS after Migration from Fedora 23 to Fedora 24

  1. Very helpful, thanks. Folks with an OpenStreetMap DB will also need to specify DB encoding before the upgrade step:

    # PGSETUP_INITDB_OPTIONS=”-E ‘UTF-8′”
    # export PGSETUP_INITDB_OPTIONS
    # postgresql-setup –upgrade

    And if you have locally built support tools (e.g., osm2pgsql) they may need to be rebuilt to pick up new library versions (e.g., libgeos-3.4.2.so => libgeos-3.5.0.so). (That is, run ldd on your executables before all the cron jobs start failing.)

    Like

Leave a comment