Stands on the shoulder of Giants

My rambling and thoughts. Powered by Obtvse

How to develop app related with Spatial and Postgresql in Mac OS X Mountain Lion.

At the moment, we are developing a new location-based app focusing in travel. After doing some reading, I found that PostgreSQL is a very capable RDBMS for doing spatial related query. PostgreSQL also a very stable and scalable database, and the best of open source database engine out there.

Since I am using Mac OS X for development, I met some difficulties for setting up my development environment to use PostgreSQL. Heres is a list what I've done to install

  1. Get PostgreSQL database app for mac from this site. This is the easiest method for running PostgreSQL Database server in Mac OS X. Just download the app, unpack it, copy to your Applications folder (System or User, whichever you choose), and just double click it to run it.
  2. The most known PostgreSQL client is PGAdmin. The problem is, PGAdmin is ugly. It has 90s User Interface, and so not pretty in Mac OS X. Fortunately, the creator of Postgres app also create a brand new app, named Induction app. It is a polygot database client, which means that you can connect to multiple database and do some query stuff just from one client. Say goodbye to PGAdmin, PHPMyAdmin, or Adminer for MySQL. What makes this app more awesome, we can connect to NoSQL databases, such as Redis and MongoDB. Currently it is in Alpha, but I really recommend it.
  3. This issue is Mountain Lion specific, but sometimes you will get Failure message when you initiate spatial support on PostgreSQL. This problem caused by Mountain Lion is missing a specific library, named libjpeg. I recommend you to use Homebrew to install.
  4. Add psql from Postgres app into your PATH, by editing your .bashrc if you are using bash or .zshenv if you are using zsh.
  5. Launch Terminal or iTerm2, type psql -h localhost. You will get the psql prompt for and your database is ready to be use. Create your database first, using command CREATE DATABASE <database_name>; and then use it by issuing USE DATABASE <database_name>;. PostGIS is a extension for PostgreSQL, you must install it before you can use it. Install it by typing CREATE EXTENSION postgis;.
  6. You are ready to use PostGIS.
Back to Blog