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

83

Install Postgresql on Mountain Lion

21516 views

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

Comments

  • Blank-mugshot
    vsushkov

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

  • Blank-mugshot
    pmarsceill

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

  • Blank-mugshot
    gma

    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.

  • 71f4dd4f97803053c49e3fa1026dac8c_normal
    tdebailleul

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

  • Diamond-logo
    artemeff

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

  • Blank-mugshot
    dansbeerlist

    Saved me a lot of headache. Thanks!

  • Blank-mugshot
    aderyabin

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

Add a comment