4

I have installed PostGIS on the mac using the binaries available on http://www.kyngchaos.com/software:postgres

Postgres v 9.1.3

PostGIS v 2.0

After that I want to enable postgis for my database. I tried using CREATE EXTENSION query. But it error'ed out saying that the extension is not available. I then tried

sudo -u postgres psql -d [your database] -f /usr/local/pgsql/share/contrib/postgis-2.0/postgis.sql
Password: 
SET
BEGIN
psql:/usr/local/pgsql/share/contrib/postgis-2.0/postgis.sql:69: ERROR:  could not access file "$libdir/postgis-2.0": No such file or directory

How can i make $libdir expand into the path which i found by executing

$ pg_config --pkglibdir
/usr/lib/postgresql

The /usr/lib/postgresql does NOT contain postgis-2.0.

Digging around for a few more hours I found a hacky solution:

export PATH=/usr/local/pgsql/bin:$PATH

This makes the pg_config magically change to:

$ pg_config --pkglibdir
/usr/local/pgsql-9.1/lib

And then I hardcode that path into the postgis.sql file. But I want to know why $libdir doesnt resolve automatically.

2
  • I have exactly the same problem. Please could you explain how you hard-coded the path in the postgis.sql file?
    – Richard
    May 25, 2012 at 14:56
  • I just did manual find and replace all of $libdir with the path specified by pg_config --pkglibdir
    – Karan
    May 25, 2012 at 23:44

2 Answers 2

5

I get the same error after updating postgres with a working postgis install. Although this does not answer the original question, I'm adding this answer since the error is the same. The postgis .so files will not be in the postgres package directory (pg_config --pkglibdir) after a new postgres install. These files need to be there:

$ ls -l /usr/local/Cellar/postgresql/9.2.3/lib | grep postgis
-rwxr-xr-x  1 tee  wheel   585416 Feb 24 14:39 postgis-2.0.so
-rwxr-xr-x  1 tee  wheel   434752 Feb 24 14:39 rtpostgis-2.0.so

The simplest solution is to reinstall postgis after a postgres update:

brew uninstall postgis
brew install postgis
2

When you run psql, you're probably running the binary that's installed on OSX by default in /usr/bin. Run 'which psql' to be sure. Altering your $PATH like that changes which pg_config you're using. That's not a hacky solution to change your $PATH like that, it's perfectly OK. I recommend installing Postgres and PostGIS using homebrew though.

3
  • Thanks for the reply. But even after modifying the path I had to hardcode the corresponding libdir in the sql file. $libdir still remained unresolved. Do you know why?
    – Karan
    Apr 29, 2012 at 7:13
  • Are you sure the correct version of postgres is running? You can check which executable is running with ps aux | grep post. Make sure the postgres process that's running is the one you want (i.e. somewhere in /usr/local/pgsql-9.1).
    – zhm
    Apr 30, 2012 at 3:26
  • I have the same issue as @KaranK. I installed via homebrew. which pg_config and which psql both show /usr/local/bin version. Additionally pg_config tells me LIBDIR = /usr/local/Cellar/postgresql/9.1.4/lib PKGLIBDIR = /usr/local/Cellar/postgresql/9.1.4/lib ...yet I still have to hard-code that exact value into postgis.sql in place of $libdir before the script will run!
    – Anentropic
    Jul 28, 2012 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.