9

I upgraded and subsequently reinstalled PostGIS & PostgreSQL on OS X Mountain Lion. When trying to use the PostGIS extensions, I receive the following error:

ERROR: could not open extension control file "/usr/local/Cellar/postgresql/
9.2.3/share/postgresql/extension/postgis.control": No such file or directory

It appears that PostGIS (and PostgreSQL as well??) are still looking for the required files in the /postgresql/9.2.3/ directory and not in the /postgresql/9.2.4/ directory. I have used Homebrew to remove all previous versions of PostgreSQL via the following command:

brew remove --force postgresql

Could someone please point me in the right directions as to why this problem is occurring? (There must be a lingering config file somewhere or something?)

Any help will be much appreciated.

Eduard Luca
  • 6,514
  • 16
  • 85
  • 137
paddleman
  • 255
  • 2
  • 11

4 Answers4

12

The problem is you have a psql server running on version 9.2.3 of the codebase. To test for this, load up a psql console and you should see this at the top:

psql (9.2.4, server 9.2.3)
Type "help" for help.

Note the "server 9.2.3" comment above. If you're running the proper version of your server, you would see this instead:

psql (9.2.4)
Type "help" for help.

To fix this, just follow the instructions given by brew info postgresql on unloading and loading the LaunchAgent - this will restart the server with the new code:

To reload postgresql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Empact
  • 462
  • 6
  • 6
2

In terminal, I ran

$ psql

In psql, it showed me this

> psql (9.6.3, server 9.5.7)
> Type "help" for help.

I tried to run the following

> CREATE EXTENSION postgis;

and got this error message

> ERROR:  could not open extension control file "/usr/local/Cellar/postgresql@9.5/9.5.7/share/postgresql@9.5/extension/postgis.control": No such file or directory

I quit psql by

> \q

And then ran

$ brew services list

Which then came back with the following results

Name           Status  User     Plist
mysql          stopped          
mysql@5.6      stopped          
postgresql     stopped          
postgresql@9.5 started doquyena /Users/doquyena/Library/LaunchAgents/homebrew.mxcl.postgresql@9.5.plist
redis          stopped  

I worked out that my psql was running on an incompatible psql server so I corrected it with the following command

$ brew services stop postgresql@9.5
$ brew services start postgresql

When I went back into psql

$ psql

It now displayed this which indicates that I was now on a matching server

> psql (9.6.3)
> Type "help" for help.

Hence, there was no error message when I then tried to create the extension again

> CREATE EXTENSION postgis;

And then I was able to create postgis data tables like this one without any problems

> CREATE TABLE s_test(geom geometry);
Gwen Au
  • 859
  • 9
  • 10
1

Homebrew's design is to generally leave user-editable config files and generated data files in place during a remove or upgrade, so they're preserved between versions. Sounds like you're right and it's a config file left somewhere.

There are no global config files for postgres in /usr/local/etc. So it's probably user data files. Did you create any databases using the previous version of postgres and use the postgis extension in them? The config files in those databases may be referring to that old postgres version. Those databases are typically under /usr/local/var/postgres. Have a look at the .conf files under there and see if you can edit them to fix the extension path or re-create the databases.

Andrew Janke
  • 23,508
  • 5
  • 56
  • 85
1

I just ran into this exact same issue and, after these solutions didn't fix it, I found one of my own:

brew uninstall postgis && brew install postgis

The key to this working stood out to me in the build output for postgis:

==> ./configure --with-projdir=/usr/local --with-jsondir=/usr/local/opt/json-c --with-pgconfig=/usr/local/Cellar/postgresql/9.4.4/bin/pg_config --disable-nls

Note that it uses the pg_config, most likely in order to determine where it needs to store all of the files necessary for the extension.

Joey Wilhelm
  • 5,729
  • 1
  • 28
  • 42