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.5432f you want to install the postgres gem, including ARCHFLAGS is recommended: env ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
To have launchd start postgresql at login: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't want/need launchctl, you can just run: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start ==> Summary 🍺 /usr/local/Cellar/postgresql/9.2.3: 2824 files, 39M, built in 3.0 minutes alavadeira ruby-2.0.0-p0 master$ initdb /usr/local/var/postgres -E utf8 The files belonging to this database system will be owned by user "rinaldifonseca". This user must also own the server process.