14

I am getting the following error when I run create extension postgis;

ERROR: could not open extension control file "/Library/PostgreSQL/9.6/share/postgresql/extension/postgis.control": No such file or directory

I am using Postgres 9.6.3 and PostGIS 2.3.2 installed using Homebrew on OS X El Capitan.

mdfind -name postgis.control shows:

/usr/local/Cellar/postgis/2.3.2/share/postgresql/extension/postgis.control

brew info postgis shows:

PostGIS extension modules installed to:
/usr/local/share/postgresql/extension

When I start the Postgres console I see:

psql (9.6.3, server 9.6.1)

I read a similar question, PostGIS Homebrew installation referencing an old path?, and tried to reload postgresql using the commands given in the top answer, but I am still seeing psql (9.6.3, server 9.6.1). Also, I believe my issue is different because it's looking for the extension control file in /Library and not /usr/local/Cellar.

Any help would be appreciated.

pufferfish
  • 16,651
  • 15
  • 56
  • 65
Fiona
  • 151
  • 1
  • 1
  • 6

2 Answers2

10

When you try to install postgis it install latest version of postgresql along with it as dependency. So if you installed postgres@V (where V is user desired version )

brew install postgresql@V

later you run this command

brew install postgis

it will install postgres10.1 or whatever is latest. So after that if run

create extension postgis;

In postgresql@V it will try to check its extension directory and it won't find postgis.control in extension directory as this postgis is installed in extension folder of postgresql version that is installed with that.

To solve this problem, you have to create a symlink from given installation of postgis to the desired postgresql@V

This example for postgresql@9.6

ln -s  /usr/local/share/postgresql/extension/postgis* /usr/local/Cellar/postgresql@9.6/9.6.6/share/postgresql@9.6/extension/
ln -s /usr/local/lib/postgresql/postgis-2.3.so /usr/local/Cellar/postgresql@9.6/9.6.6/lib/postgis-2.3
ln -s /usr/local/lib/postgresql/rtpostgis-2.3.so /usr/local/Cellar/postgresql@9.6/9.6.6/lib/

before running these commands, please check postgresql version and file path in your system

Thanks this gist for help.

abby37
  • 597
  • 6
  • 21
  • This seems to be a dead end now, when the default Homebrew Postgres version is 13, and you try to install postgis for an earlier version: "ERROR: PostGIS built for PostgreSQL 13.0 cannot be loaded in PostgreSQL 12.7" – Cloud Artisans May 27 '21 at 12:05
  • @DeepakPatankar, gave up after a couple of hours and simply used `brew install` for the latest postgresql and postgis. Didn't want to waste any more time :( – Cloud Artisans Aug 20 '21 at 14:50
5

I had a similar problem with full details here. When the server is mentioned in your Postgres console, it means that you're referencing an older codebase. Stop that server and launch the correct server with the following commands.

$ brew services list

That will give you a list of database servers that are running.

$ brew services stop postgresql@<older-version>
$ brew services start postgresql
Gwen Au
  • 859
  • 9
  • 10
  • But that would force me to change the DB version. How to install `postgis` and get it working on the older version? – Rafs Aug 18 '22 at 13:00