Aston J

How to install PostgreSQL on Mac OS X

Posted on: August 10th, 2012 by AstonJ 5 Comments

There are a number of ways to install Postgres on Mac, here’s three. While these instructions are for a clean install of Lion, they may work for Mountain Lion.

Postgresapp

The easy option! Simply go to Postgresapp.com download, and double click – that’s it! It also includes PLV8 and PostGIS (see second comment below for details). If you want more info about the project, check out this

Postgres one click installer

Another easy option! This is a one click installer from The EnterpriseDB PostgreSQL Company. It includes PostgreSQL, pgAdmin, PL/Java and the PL/pgSQL debugger plugin. Note that this creates a new postgresql user on your system – you may or may not like that

To install, simply download and double click, from here.

Homebrew

Homebrew – the much loved “missing package manager for OS X”.

In terminal:

brew install postgresql

Then follow the instructions at the end, for me there were:

initdb /usr/local/var/postgres

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

And these are handy to note

Or start manually with:
  pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

And stop with:
  pg_ctl -D /usr/local/var/postgres stop -s -m fast

Which one to use?

If you want a quick an easy solution, the Postgresapp seems like a good choice – it just works. If you don’t mind a new user being created on your system them it might be worth trying the one click installer. If you already use Homebrew then that may be your preferred choice.

Personally I would go with the first or last choice as I’m not keen on having additional users on my system.

Install the pg gem

If you want to install the postgres gem, including ARCHFLAGS is recommended:

env ARCHFLAGS=”-arch x86_64″ gem install pg

Tags: , , , ,

5 Responses

  1. I recently started using PostgresApp (by Heroku) and I love it!
    I used to go the homebrew route until Mountain Lion (OS X 10.8) broke my build and I was too much in a hurry to fix it.
    Now we need a similar setup for RVM/Ruby/Rails hehe

  2. Chris Oliver says:

    Something to note is that Postgresapp will include some other functionality that others don’t: PLV8 and PostGIS

    PLV8 is a shared library that provides a PostgreSQL procedual language powered by V8 JavaScript Engine. With this program you can write in JavaScript your function that is callable from SQL.
    http://code.google.com/p/plv8js/wiki/PLV8

    PostGIS adds support for geographic objects to the PostgreSQL object-relational database
    http://postgis.refractions.net/

    Both very awesome tools.

  3. AstonJ says:

    Gosh you two are fast :p
    Have updated the post with PLV8 and PostGIS info :-)

  4. Christoph Murauer says:

    Hello !

    A nice post … found it through google. Hmm, … „ … the first or last choice as I’m not keen on having additional users on my system.“. This is an illusion because since Lion Apple uses PostgreSQL as their prfered database (it is also better because there are not so many exploits out as for MySQL). If you open a terminal on your Lion or Mountain Lion client and run the following command

    dscacheutil -q user -a name _postgres

    you will see that the user already exists … and for what it is. This user is deactivated by default (you can check that using Apple´s Server Admin Tools). To run a local PostgreSQL server this is enough (see also Lion and Mountain Lion server – the user is deactivated and the server accepts only SOCKET connections and no TCP / IP connections). The second way you show don´t creates a new user – normally it activates simple the existing user. BUT this also means that you can connect remotly using TCP / IP (by default this user has NO password but access to the whole database cluster) to this machine (thats the reason why you see the user in your user list under preferences). Ok, some installers create a second user to the existing user.

    I took another way and build PostgreSQL from source.

    Greetings …

  5. ungars says:

    Just do like this :
    http://www.enterprisedb.com/resources-community/pginst-guide

    Interactive and no interactive install process.

Leave a Reply