Skip to content

Server notes

Install PostgreSQL on Mac OS X

The short Homebrew route to a working PostgreSQL install on Mac OS X, including service start, database initialisation, and a role for the postgres user.

By Jozsef 2 min read

These are the steps I use to install PostgreSQL on Mac OS X.

  1. Install Homebrew:

    bash
    ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
    
  2. Install PostgreSQL:

    bash
    brew install postgresql
    
  3. Set up automatic start:

    bash
    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
    
  4. Initialise the database cluster:

    bash
    initdb -A trust /usr/local/var/postgres
    initdb /usr/local/var/postgres -E utf8
    
  5. Create the postgres role:

    bash
    createuser -s postgres
    

Start and stop manually

Start the service:

bash
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Stop the service:

bash
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

The first database cluster is enough for local development. For anything shared, use a proper service manager and a real password policy.

Sources and further reading