Postgresql – Cannot upgrade postgresql 9.4 -> 9.5beta2 after postgis 2.1.6 -> 2.2.0 upgrade

postgispostgresql

Here is my situation:

  1. I started with Postgresql 9.4.5 and Postgis 2.1.6. Everything running smoothly. Both are installed from source.
  2. I upgraded Postgis to 2.2.0 (download source, configure, make, make install, then ALTER EXTENSION postgis UPGRADE TO '2.2.0';). This seems to have worked (select postgis_full_version() shows POSTGIS="2.2.0 r14208" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.1, 04 March 2015" GDAL="GDAL 2.0.1, released 2015/09/15" LIBXML="2.9.3" LIBJSON="0.11" RASTER on both databases where postgis was installed), though the old postgis-2.1.so was left in the lib dir.
  3. I attempt to upgrade Postgresql from 9.4.5 to 9.5beta2. I download source, configure, make, make install, install Postgis 2.2.0, initdb, and get ready to run pg_upgrade. pg_upgrade fails with:

Your installation references loadable libraries that are missing from the
new installation. You can add these libraries to the new installation,
or remove the functions using them from the old installation. A list of
problem libraries is in the file:
loadable_libraries.txt

loadable_libraries.txt contains:

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

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

I'm not sure why the new version of Postgresql needs the old version of Postgis…shouldn't it have been removed? I moved the old postgis-2.1.so and rtpostgis-2.1.so files from the lib directory of 9.4 but the error persists.

I also tried to compile Postgis 2.1.6 against Postgresql 9.5beta2 but compilation failed with the following error:

lwgeom_accum.c: In function ‘pgis_geometry_accum_transfn’:
lwgeom_accum.c:109:46: error: ‘AggState {aka struct AggState}’ has no member named ‘aggcontext’
aggcontext = ((AggState *) fcinfo->context)->aggcontext;

I also tried copying the 2.1 libraries from the 9.4 directory to the 9.5 directory, but that failed because the Postgresql version didn't match.

Dumping and reloading all databases is possible but only as a last resort because the databases are huge. If the answer is "because 9.5 is still in beta", I could accept that, though their betas seem to have been pretty stable in the past.

Best Answer

I managed to solve my problem by following these steps:

  1. Download the source to 2.1.6 and apply the patch found here
  2. Postgis 2.1.6 will now compile with Postgresql 9.5beta2. Compile and install.
  3. pg_upgrade now works, having the old version of Postgis installed.

I don't think this is an ideal situation, but at least it runs now.