[postgis] fixing missing rt-postgis2.0


If you are using brew to manage your postgresql/postgis install, and you suddenly cannot access any postgis functionality, with the error that rtpostgis-2.0.so cannot be found, check your json-c version, I had to do

brew switch json-c 0.10

to get it working.

The long and dirty story

I had created a new database, but for some reason I could not add a geometry column, so I was thinking, maybe, somehow my POSTGIS extension needs to be (re)activated. And when I tried this I got the the obscure error

could not load library "/usr/local/Cellar/postgresql/9.2.3/lib/rtpostgis-2.0.so": dlopen(/usr/local/Cellar/postgresql/9.2.3/lib/rtpostgis-2.0.so, 10): Library not loaded: /usr/local/opt/sqlite/lib/libsqlite3.0.8.6.dylib Referenced from: /usr/local/lib/libgdal.1.dylib


Maybe my postgis installation is somehow corrupt, so I tried brew install postgis. Wronggggg move. Suddenly I am installing postgresql 9.3.4 too?

Ok. I did not see an alternative. This of course ment I should upgrade my database. First step: install postgresql 9.3.4 and postgis. Then I tried to follow this upgrade procedure. In short I issued the following commands:

initdb /usr/local/var/postgres9.3 -E utf8
pg_upgrade -d /usr/local/var/postgres -D /usr/local/var/postgres9.3 -b /usr/local/Cellar/postgresql/9.2.3/bin/ -B /usr/local/Cellar/postgresql/9.3.4/bin/ -v

and that failed? I got almost the same error, but now a bit more verbose:

PG::UndefinedFile: ERROR: could not load library "/usr/local/Cellar/postgresql/9.2.3/lib/postgis-2.0.so":   
    dlopen(/usr/local/Cellar/postgresql/9.2.4/lib/postgis-2.0.so, 10): Symbol not found: _json_tokener_errors
Referenced from: /usr/local/Cellar/postgresql/9.2.4/lib/postgis-2.0.so
Expected in: /usr/local/lib/libjson.0.dylib
   in /usr/local/Cellar/postgresql/9.2.4/lib/postgis-2.0.so

What? Json? And that led me to the answer: I had to switch my json-c version:

brew switch json-c 0.10

Restarted my pg_upgrade which now seemed to work, but failed at the end, that postgis-2.0.so and rtpostgis-2.0.so were not loadable. Sigh. These were of course compiled against the new json-c (I think?).

I switched the json-c version back to 0.11 and then I started my postgres process again. This showed my that my databases were NOT upgraded.

This almost feels like dll hell al over again.

Should I uninstall postgis, do db_upgrade and install it again? Go back to 9.2.3?

For the moment I switched back to 9.2.3 and opened an issue on the homebrew. I hope somebody can help me.

brew switch postgresql 9.2.3
 brew switch json-c 0.10

Not sure what will break, because something needed to install json-c 0.11 ? At least for now I am good. I hope.

[UPDATE] Nope. It only partly works now. The errors I saw were:

after brew switch json-c 0.10 :

PG::UndefinedFile: ERROR: could not load library "/usr/local/Cellar/postgresql/9.2.3/lib/rtpostgis-2.0.so": dlopen(/usr/local/Cellar/postgresql/9.2.3/lib/rtpostgis-2.0.so, 10): Library not loaded: /usr/local/lib/libjson-c.2.dylib Referenced from: /usr/local/opt/liblwgeom/lib/liblwgeom-2.1.1.dylib Reason: image not found

after brew switch json-c 0.11

PG::UndefinedFile: ERROR: could not load library "/usr/local/Cellar/postgresql/9.2.3/lib/postgis-2.0.so": dlopen(/usr/local/Cellar/postgresql/9.2.3/lib/postgis-2.0.so, 10): Symbol not found: _json_tokener_errors Referenced from: /usr/local/Cellar/postgresql/9.2.3/lib/postgis-2.0.so Expected in: /usr/local/lib/libjson.0.dylib in /usr/local/Cellar/postgresql/9.2.3/lib/postgis-2.0.so

So I was stuck. Reverting to the old version did not fix it.

I was able to get my situation rectified by doing a "clean" install of postgresql92 which installed postgresql 9.2.8.

brew install postgresql92
brew link --overwrite postgresql92
brew install postgis20
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

And now I am good. On version 9.2.8. Hehe.


I have no clear conclusion or solution. Somehow my json-c got upgraded, which messed up my postgis installation. I guess installing the new version of postgis, messed up my old version of postgis (since now one file was linked to json-c.0.11 and the other against json-c.0.10).

However I did find a clean solution: upgrading to postgresql92 and postgis20, now nicely linked against json-c 0.11.

If you encounter the same error: switch your json-c version, before trying anything else, and then I hope you should be good to go (no need to upgrade).

Add comment

Recent comments


ruby on rails 34 ruby 26 rails3 17 rails 15 oracle 11 rspec 9 rspec2 7 jquery 7 ubuntu 5 javascript 5 windows 5 activerecord 3 refactoring 3 geoserver 3 gis 3 arrrrcamp 3 actionmailer 2 oracle spatial 2 tdd 2 postgis 2 routing 2 rvm 2 mongoid 2 csharp 2 thin 2 win32 2 gem 2 rails4 2 git 2 service 2 haml 2 cucumber 2 view testing 2 i18n 1 displaysleep 1 spatial 1 gemsets 1 wubi 1 oracle_enhanced_adapter 1 migrations 1 watchr 1 ci 1 plugins 1 coderetreat 1 ie8 1 ssl 1 oci 1 nested model form 1 wcf 1 11.04 1 jsonp 1 ruby-oci8 1 teamcity 1 engines 1 pgadmin 1 soap 1 content_for 1 word automation 1 plugin 1 capybara 1 xml 1 bootstrap 1 migrate to rails3 1 mvc 1 unity 1 rendering 1 word2007 1 x64 1 limited stock 1 fast tests 1 pl/sql 1 delayed_job 1 pdf 1 test coverage 1 optimization 1 processing 1 borland 1 method_missing 1 cross-browser 1 devise 1 schema_plus 1 mongo 1 mongrel 1 dual boot 1 usability 1 mongrel_service 1 dba 1 mission statement 1 model 1 metadata 1 rcov 1 exceptions 1 image_tag 1 attachments 1 bde 1 css 1 yield 1 ajax 1 generative art 1 rails-assets 1 coordinate systems 1 submodules 1 netzke 1 ora-01031 1 authlogic 1 postgresql 1 shopping cart 1 agile 1 fast_tagger 1 subjective 1 wice_grid 1 generators 1 nvidia 1 mongodb 1 etsyhacks 1 staleobjecterror 1 session 1 jeweler 1 wordpress hacked 1 jasmine 1 heroku 1 rjs 1 life 1 unobtrusive-javascript 1 render_anywhere 1 html5 1 rails31 1 json 1 cocoon 1 mingw32 1 observe_field 1 osx 1 actionwebservice 1 testing 1 debugging 1 strings 1