Where developers come to connect, share, build and be inspired.


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: mkdir /var/pgsql_socket 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


  • 7fe398428f6c4be5ccc8930a8b434e87

    Postgres.app is the easiest way to run PostgreSQL on the Mac

  • Bc4365616a85e45336be7fd3800a9057

    Thank you for this, no one mentions that Mountain Lion opens the socket at /var/pgsqlsocketalt

  • 7abc37c95590b1b29400e0bddfff9156

    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 pg gem).

    I was wise to this so rebuilt the pg gem, but failed to do it in a shell that had /usr/bin before /usr/local/bin.

    Uninstalling 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 /var/pgsql_socket directory.

  • User-avatar

    With Postgres.app you have to be sure that which psql points to /Applications/Postgres.app/Contents/MacOS/bin/psql

  • Diamond-logo

    https://github.com/jwang/pgpane for easiest way to start or stop postgres

  • 1cd64bcd9dec0ae45516b14da63167b3

    Saved me a lot of headache. Thanks!

  • Cebfabb19814410151c8375b798643df

    Thanks for comment. I switched to vagrant+chef to isolate my development environment from my Mac.

Add a comment