How to Install Postgres on your Mac

I needed to run some queries against a couple of postgress databases, and I didn't want to have to use a server. There's a quick and easy way to get pgsql installed and running on your mac.

Hopefully you've got mac ports installed already, if not head over there and install it.

After you have that installed, you can simply do:

$: sudo port install postgresql83

or do this:

$: sudo port search postgres

to get a list of what other versions and options you have available. I needed this to be able to run commands using pgsql directly from my main work system. Different options would be required if you want to run the server part of it.

This is what my install output looked like:

$: sudo port install postgresql83
---> Fetching bison
---> Attempting to fetch bison-2.3.tar.bz2 from http://ftp.gnu.org/gnu/bison
---> Verifying checksum(s) for bison
---> Extracting bison
---> Configuring bison
---> Building bison with target all
---> Staging bison into destroot
---> Installing bison 2.3_2
---> Activating bison 2.3_2
---> Cleaning bison
---> Fetching ossp-uuid
---> Attempting to fetch uuid-1.6.0.tar.gz from ftp://ftp.ossp.org/pkg/lib/uuid/
---> Verifying checksum(s) for ossp-uuid
---> Extracting ossp-uuid
---> Applying patches to ossp-uuid
---> Configuring ossp-uuid
---> Building ossp-uuid with target all
---> Staging ossp-uuid into destroot
---> Installing ossp-uuid 1.6.0_2
---> Activating ossp-uuid 1.6.0_2
---> Cleaning ossp-uuid
---> Fetching postgresql83
---> Attempting to fetch postgresql-8.3.1.tar.bz2 from
---> Attempting to fetch postgresql-8.3.1.tar.bz2 from
---> Verifying checksum(s) for postgresql83
---> Extracting postgresql83
---> Configuring postgresql83
---> Building postgresql83
---> Staging postgresql83 into destroot
---> Installing postgresql83 8.3.1_0
To use the postgresql server, install the postgresql83-server port
---> Activating postgresql83 8.3.1_0
---> Cleaning postgresql83

Then after this, I could issue this to get on the db and start running my queries:

$: /opt/local/bin/psql83 -U username -W -d databasename -h host-ip-address