Leopard, PostgreSQL and PostGIS from KyngChaos.com
In my last post I detailed my process for building PostgreSQL and PostGIS on Leopard. Problem is, it didn’t work. I was getting a strange crash when importing shape data. I’m not positive what the problem is but I would bet it was the liconv trickery…
In any case, I discovered that there are pre-built binaries for OS-X (Leopard compatible!) referenced from the PostGIS website. The maintainer has also packaged some require frameworks (GEOS and PROJ).
I’ve now got everything working (I think!) using the pre-compiled binaries. The steps are somewhat similar to those detailed in the other post. Here’s what I did:
PostgreSQL
- Download the PostgreSQL dmg and run the installer. (I also installed the startup item)
PostGIS
- Download the GEOS and PROJ images and run the installers.
- Download the PostGIS dmg and run the installer
Initial DB Setup
- Initialize the default db. (The installer readme says that it does this but it didn’t seem to…)
$ sudo su postgres -c '/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data' - Create a new superuser:
$ createdb -U postgres <user-name> -
Create a postgis template database:
-
Connect to the template database
$ psql template1-
Execute the following commands:
template1=# create database template_postgis with template = template1;
template1=# UPDATE pg_database SET datistemplate = TRUE where datname = 'template_postgis'; -
Connect to the new template_postgis database:
template1=# c template_postgis -
Add PostGIS extensions and grant access to everyone to spatial tables:
template_postgis=# CREATE LANGUAGE plpgsql;
template_postgis=# i /usr/local/pgsql/share/lwpostgis.sql;
template_postgis=# i /usr/local/pgsql/share/spatial_ref_sys.sql;
template_postgis=# GRANT ALL ON geometry_columns TO PUBLIC;
template_postgis=# GRANT ALL ON spatial_ref_sys TO PUBLIC; -
Prevent further modifications to the template_postgis database:
template_postgis=# VACUUM FREEZE;
-
-
Ruby
- Install postgres nativ extensions
- Get the gem sources
$ sudo gem install postgres - The build will fail. Go to
/usr/lib/ruby/user-gems/1.8/gems/postgres-0.7.1and execute:
$ sudo ruby extconf.rb --with-pgsql-dir=/usr/local/pgsql/
$ sudo make && sudo make install
$ sudo gem install postgres
- Get the gem sources
- Install GeoRuby
$ sudo gem install GeoRuby