0
votes

I'm working on OSX and have postgres installed via Homebrew. I've just upgraded Postgres from v11 to v13. Now I've tried updating the database files with:

brew postgresql-upgrade-database

This fails and looking at the logs, the error is:

pg_dump: error: query failed: ERROR:  could not access file "$libdir/postgis-2.5": No such file or directory

If I do brew info postgis then I see:

% brew info postgis
postgis: stable 3.0.2 (bottled), HEAD
Adds support for geographic objects to PostgreSQL
https://postgis.net/
/usr/local/Cellar/postgis/3.0.2_1 (435 files, 29.7MB) *
  Poured from bottle on 2020-11-12 at 23:15:12
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgis.rb
License: GPL-2.0-or-later
==> Dependencies
Build: gpp ✘, pkg-config ✔
Required: gdal ✔, geos ✔, json-c ✔, pcre ✔, postgresql ✔, proj ✔, protobuf-c ✔, sfcgal ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 11,064 (30 days), 26,959 (90 days), 80,033 (365 days)
install-on-request: 10,946 (30 days), 26,628 (90 days), 78,351 (365 days)
build-error: 0 (30 days)

So I guess Postgis 3.0.2 was installed as part of the upgrade process and pg_dump (which is needed for the database file upgrade) can't find Postgis 2.5.

What should I do? I guess I could reinstall Postgis 2.5 to $libdir temporarily - but how?

pg_config --pkglibdir reveals that $libdir is /usr/local/lib/postgresql. If I list the files in that directory, I can see it contains postgis-3.so, but not postgis-2.5.so.

NB: I also can't currently access postgres with psql - I see the dreaded psql: error: could not connect to server: could not connect to server: No such file or directory. However, brew services list tells me that postgresql is running.

3

3 Answers

1
votes

Uninstall the wrong version of Postgis if you haven't already:

brew remove postgis

Firstly go to the last 2.5 version of the Postgis formula here:

https://raw.githubusercontent.com/Homebrew/homebrew-core/bca96164362bfa3c42b4d403be4eb3847797424f/Formula/postgis.rb

Copy that code.

Paste this over the homebrew Postgis formula on your machine:

pbpaste > $(find $(brew --repository) -name postgis.rb)

Then install Postgis again with this formula:

brew install postgis

Pin Postgis to prevent it being upgraded accidentally:

brew pin postgis

That should get the correct version of Postgis in there for you.

0
votes

Upgrading PostGIS is not so straightforward (see the documentation), and by using the automatic upgrade of this distribution you probably messed up your installation.

Take a full backup of your PostgreSQL data directory, then uninstall PostgreSQL v13, install v11 and PostGIS 2.5 again and see that you can get the database to work again.

Then follow the upgrade procedure from the PostGIS manual.

0
votes

There's a compatibility/support matrix on the user wiki linked off of the PostGIS site which seems to indicate that as of Postgres v13, the minimum version of PostGIS is v3.0

If you're stuck on PostGIS v2.5 for whatever reason, Postgres V12 looks to be your best bet.