Tuesday, April 2, 2013

Installing multiple PostgreSQL versions on Homebrew

I was going to post this yesterday, but some might have thought that it was a joke. April 1st is always an annoying day to communicate real information.

If you have been fond of the way Debian and Ubuntu manage multiple PostgreSQL versions in parallel, you can now have the same on OS X with Homebrew:

brew tap petere/postgresql
brew install postgresql-9.2
# etc.
brew install --HEAD postgresql-common

postgresql-common is the same code as in Debian, only mangled a little.

Now you have all the client programs symlinked through pg_wrapper, and you can use the server management tools such as:

pg_createcluster 9.2 main
pg_ctlcluster 9.2 main start

Let me know if you find this useful.



  1. I am trying to install postgresql 9.2 on OSX 10.9.3. Whenever i try "brew install postgresql-9.2", it gives "Error: No available formula for postgresql-9.2 ". If i try "brew install postgresql92", it gives me this error http://stackoverflow.com/questions/24628567/install-specific-version-of-postgresql-on-mac-using-brew

    1. You probably forgot the "brew tap" command.

  2. First, thanks so much for the work on these tools.

    I've installed two versions of postgres via brew - 9.1 and 9.3; then installed postgresql-common. Built clusters as expected PGCLUSTER=9.1/foo; PGCLUSTER=9.1/bar. However, when I execute psql against these, the client is in 9.3 with the server in 9.1:
    09:21:40 ~$ PGCLUSTER=9.1/foo psql postgres
    psql (9.3.5, server 9.1.14)

    Tried various incarnations of linking pg_wrapper to the psql in the 9.1/bin folder, did not make a difference. Wondering if the postgresql-common is predisposed to use the latest version of postgres available in brew? If not, what magic can I use to get the server and client versions to align.

    Thanks in advance.

    1. postgresql-common always selects the latest psql by default, per https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=639108 .

  3. How would one go about installing postgis in this setup? The postgis brews require one of the main postgresql brews, which conflict with the postgresql-common install. (Sorry if this is a duplicate comment - it wasn't clear if it submitted the first time I tried)

    1. I recommend using Pex: https://github.com/petere/pex