Last Updated: February 25, 2016
· Hendra Uzia

PostgreSQL Installation on Mac OSX Mountain Lion 10.8.3 using Homebrew

This is the steps needed to install a working copy of postgresql in Mac OSX Mountain Lion 10.8.3 using Homebrew. It is assumed that you have Homebrew already installed.

Update your homebrew.

brew update

Fix any errors shown.

brew doctor

Install postgresql.

brew install postgresql

Create a database.

initdb /usr/local/var/postgres -E utf8

Chances are there's an error if you create a database. If not, skip to steps on automatically load postgresql on login.

FATAL:  could not create shared memory segment: Cannot allocate memory

Thanks to Dave Baker's article, there are 2 options to fix that, either you reduce postgresql shared memory usage, or increase the system settings. Well, I choose the later option as He suggested.

sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216

Unfortunately the system setting will be reset after restart with only those command above. To retain the memory settings, execute the following command and recreate the database.

sudo tee -a /etc/sysctl.conf <<EOF

initdb /usr/local/var/postgres -E utf8

Automatically load on login.

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Test if your database is running.

psql -d postgres

1 Response
Add your response

Hi Hendra, first i thank you for this wonderful and simplified "go-through".
All went fluently, until the last commands, when i create the database, it's physically present, the shell says it's been created, but whenever I try psql -d staritup :
psql: FATAL: database "staritup" does not exist

over 1 year ago ·