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.plist
Take 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 argument
Then 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=393216
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/pgsql_socket_alt
, which nobody looks at.
In terms of terminal commands:
mkdir /var/pgsql_socket
sudo chown $USER /var/pgsql_socket
Edit /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
Just in case you're still looking for an answer, /etc/sysctl.conf is read on boot. If you want the settings to take effect without rebooting, create the file, then do:
bash# sysctl -w kern.sysv.shmmax=1610612736
bash# sysctl -w kern.sysv.shmmin=1
.. etc
in the terminal as sudo root.