11
votes

While browsing through a Postgres-Rails app in development, I came across a page error-ing out due to a PG error. Thinking my current Git branch's schema may have been out of sync with my database, I attempted to rake db:reset. This caused an error (that I'm no longer able to reproduce) claiming it couldn't find the postgis.control file (IIRC) in usr/local/Cellar/postgresql/9.3.5/share/postgresql directory. After seeing that that control file existed in the corresponding directory for my 9.3.4 version of Postgres, I attempted many things, but eventually uninstalled my postgres-9.3.4 and brew uninstalled and then installed again PostGIS. At some point, though my every attempt to reset the database continued to fail, the error message changed to

ERROR: could not load library "/usr/local/Cellar/postgresql/9.3.5/lib/rtpostgis-2.1.so": dlopen(/usr/local/Cellar/postgresql/9.3.5/lib/rtpostgis-2.1.so, 10): Library not loaded: /usr/local/lib/libspatialite.5.dylib

I then attempted to uninstall Postgres and reinstall, but even this didn't solve the problem.

(Note: I have tried to create the extension to PostGIS in the Postgres console, but this has given the exact same error as what's listed above).

1
I doubt this will help, but have you tried the old school approach of loading the Postgis functions directly, just in case there is something wrong with your control file. Something like psql -f /path/to/postgis.sql databasename.John Powell
Thanks for the tip, but alas, forcibly running the postgis.sql script does nothing to change the above error from popping up when I try to run a rake db:resetKrishna_Kulkarni
I had the same problem when running ALTER EXTENSION postgis UPDATE TO "2.1.3" in psql.tee

1 Answers

21
votes

Alright figured it out!

So I'm not sure this was even something directly related to Postgres or PostGis.

In my initial post, I omitted the subsequent error lines which actually ended up being essential. They were

      Referenced from: /usr/local/lib/libgdal.1.dylib
      Reason: image not found

libgdal.1.dylib is a file from GDAL (Geospatial Data Abstraction Library). The missing file, libspatialite.5.dylib, is from SpatiaLite, a library for expanding SQLite. In /usr/local/lib/ I had another file, libspatialite.7.dylib, but no libspatialite.5.lib. After poking around in /usr/local/opt and other subdirectories around there, I found out that I had two versions of SpatiaLite, the earlier one using libspatialite.5.dylib, the later using libspatialite.7.lib.

It seemed my GDAL had gotten out of sync with my latest versions of spatialite. I executed

$ brew uninstall gdal
$ brew install gdal

and my problem was solved!