Postgresql Install Errors on OSX

Update 09/17/2014: I’ve pretty much deprecated use of MacPorts and gone exclusively to Homebrew since this post. And I haven’t run into this problem since this post.

Update 12/28/2012: There’s an easier way to run PostgreSQL! Mattt Thompson has written Postgres app for Mac OSX that allows the database to run completely self-contained! Hassle-free! Last week I was trying out Sinatra and Padrino with PostgreSQL. But for the life of me, I couldn’t get PostgreSQL to run. At first I thought it was an issue with using MacPorts again. But after some googling, it seems like others who used Homebrew also had similar issues.

could not connect to database postgres: could not connect to server: Permission denied
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

There are a couple of ways to deal with this. One of them is to include the PostgreSQL path on OSX’s commandline lookup chain. In your .bash_profile (or .profile for others) file, you could add the path to the PostgreSQL binaries:

 export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/opt/local/lib/postgresql91/bin:$PATH

Make sure the version number on PostgreSQL matches the version you are running.

* Installation of Postgresql on MacOS X using Macports
* Installing PostgreSQL 9.0 on Mac OS X 10.6.8 via MacPorts