Skip to content

Instantly share code, notes, and snippets.

@RaVbaker
Forked from demimismo/gist:3359506
Created October 15, 2012 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaVbaker/3894177 to your computer and use it in GitHub Desktop.
Save RaVbaker/3894177 to your computer and use it in GitHub Desktop.
Install Postgresql on Mountain Lion

Install Postgresql on Mountain Lion

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment