Creating Postgis extension: "ERROR: could not open extension control file"

Viewed 23738

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.

2 Answers

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.

Related