Skip to content

Instantly share code, notes, and snippets.

@demimismo
Created August 15, 2012 11:57
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save demimismo/3359506 to your computer and use it in GitHub Desktop.
Save demimismo/3359506 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
@mehulkar
Copy link

Once you set the shmmax and shmall in /etc/sysctl.conf do you have to do anything to have them take effect? Doesn't seem to change the values by just creating that file.

@redspider
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment