Install Postgresql on Mountain Lion
brew install postgresql initdb /usr/local/var/postgres -E utf8 mkdir -p ~/Library/LaunchAgents cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Then manually start the database with:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Next, need to fix Mountain Lion’s genius behaviour to have postgres open a socket in /var/pgsqlsocketalt, which nobody looks at.
In terms of terminal commands:
sudo chown $USER /var/pgsql_socket
Open /usr/local/var/postgres/postgresql.conf in a text editor, and uncomment + edit the unixsocketdirectory key to:
unix_socket_directory = '/var/pgsql_socket'
Based on Setting Up a Development Environment on Mountain Lion
Written by Andrey Deryabin
Fix PostgreSQL after Homebrew Update (OS X Mavericks & upgrading to PostgreSQL 9.3 from PostgreSQL 9.2)
Add your response
Postgres.app is the easiest way to run PostgreSQL on the Mac
Thank you for this, no one mentions that Mountain Lion opens the socket at /var/pgsqlsocketalt
With Postgres.app you have to be sure that
which psql points to
Saved me a lot of headache. Thanks!
I too was having trouble connecting to Postgres after upgrading to 9.2 on Mountain Lion, but it all turned out to be do with my PATH variable.
You need to make sure that /usr/local/bin preceeds /usr/bin in your PATH on ML, as by default it doesn't (Mac's
path_helper is run from
/etc/profile and will put
/usr/bin first). ML ships with Postgres client binaries, which can cause confusion when starting Postgres, initialising the db, and building client libraries (e.g. the
I was wise to this so rebuilt the
pg gem, but failed to do it in a shell that had
pg and then reinstalling it having set PATH up to use
/usr/local solved all my issues, and I didn't need to create the old
Thanks for comment. I switched to vagrant+chef to isolate my development environment from my Mac.