So, you want to install PostgreSQL and PostGIS on Mac OS X Lion? Good idea. Here’s how to do it.
Start by downloading and installing MacPorts from www.macports.org.
$ sudo port install postgres90 postgres90-server
And follow the installation instructions. If you get a permission denied error, you can try running it using
sudo -u postgres before the command itself. If you get an error message saying “Is the server running locally and accepting connections on Unix domain socket xxx?” try running it with
-h localhost. This is an issue that started on Mac OS X Lion.
If you want to install a default user that will be used to login to your PostgreSQL using
$ createuser -h localhost -U postgres -s <your OS X username>
$ createuser -h localhost -U postgres -s admin
Next, create a database for development. We will be using this database later on when installing PostGIS:
$ createdb -h localhost my_development_database
$ sudo port install postgis
Install PostGIS in the database:
$ cd /opt/local/share/postgresql90/contrib/postgis-1.5/ $ psql -d my_development_database -f postgis.sql -h localhost $ psql -d my_development_database -f spatial_ref_sys.sql -h localhost
And you’re done! You can now use PostGIS in your my_development_database database.