Based on: http://coderwall.com/p/1mni7w
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.plistTake a look at the server log (/usr/local/var/postgres/server.log). If you see this error:
FATAL: could not create shared memory segment: Invalid argumentThen you'll need to add this to your /etc/sysctl.conf (create it if it doesn't exist):
sudo vim /etc/sysctl.conf
kern.sysv.shmmax=1610612736
kern.sysv.shmmin=1
kern.sysv.shmmni=256
kern.sysv.shmseg=64
kern.sysv.shmall=393216Then manually start the database with:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log startNext, need to fix Mountain Lion’s genius behaviour to have postgres open a socket in /var/pgsql_socket_alt, which nobody looks at.
In terms of terminal commands:
mkdir /var/pgsql_socket
sudo chown $USER /var/pgsql_socketEdit /usr/local/var/postgres/postgresql.conf and uncomment + edit the unix_socket_directory key to:
unix_socket_directory = '/var/pgsql_socket'This wasn't working on my machine, I ended up having to symlink the socket:
ln -s /var/pgsql_socket/.s.PGSQL.5432 /tmp/.s.PGSQL.5432