ATTENTION: This is an old version!

Please find the new one here:

Setting up a complete GeoDjango development environment on OS X

This document will guide you step by step through the installation of these tools and setup of your first project.

Step by step

This instructions are also suited for unsavvy Unix users.

Follow this installation guide step by step and don’t leave out steps.

Advantages of this approach

  • Consistent environments locally and on the server: Locally we have the same environment as on the server and can test almost the same behaviour. E.g.: we don’t use SQLite locally.
  • Minimize conflicts: PostgreSQL is only installed once (contrary to Buildout which allows you to also include PostgreSQL in a recipe and install it multiple times for different projects).
  • Encapsulated development environments: We use virtualenv and define the exact version of every Python package we want to install in this environment. Developers only need to update their environment from time to time with one simple command. We have an environment for every Django version. You could also have an environment per project with this approach.
  • Best performance: We don’t use virtual machines for development due to performance issues. They’re only used for testing the applications on different browsers.


  1. This guide works on a fresh OS X installation. If another package management system like Fink or MacPorts is already installed this might lead to conflicts.
  2. If Python is already installed like described please install it again. There might occur import errors which can be caused by imports from Python 2.6 and Python 2.7 at the same time.

Install a password manager

A good password manager like saves you nerves and time every day ;-)

Create a key pair if you don’t have one

Create a key pair without a passphrase like this:


The key pair will be created here:

Private key: id_rsa
Public key:

You can send the public key to your repository manager now.

Install XCode

Install XCode from the original OS X DVD or via App Store (free):

Run XCode and also install the “Command Line Tools (154,6 MB)” you’ll find in the Preferences / Downloads.

OSX GCC Installer

As of Xcode 4.2 in Lion, Apple no longer ships its previous version of gcc-4.2, which was in Xcode 4.1 and earlier versions. It now only ships llvm-gcc (gcc front-end with llvm code backend) and clang (clang front-end with llvm backend).

There’s also a OSX GCC Installer if you don’t want to install XCode:

Install git

Download and install or upgrade git from

Bypass Gatekeeper on a case-by-case basis

If you mount (open) the .dmg and run the .pkg and get the message “can’t be opened because it is from an unidentified developer” you just press and hold the control key while you double click the .pkg Then you can click “open” in the dialog showing up to continue. [1]

Determine which git installation you use

Where does your git version reside: which git
Which version is it: git --version

Install Mercurial

If you’d like to use the package pysimplesoap you need Mercurial as well. Get it from here:

Install Python

We won’t touch the default Python shipped with OS X because exactly this version might be needed somewhere else by the OS. It resides here:

28.07.2012: 2.7.2 (10.8 Mountain Lion)
09.01.2012: 2.7.1
01.05.2011: 2.6.1

We will instead install the latest Python version the latest Django will get along with.

Get it from here and install it:

The installer puts the applications in "Python 2.7" in your Applications folder,
command-line tools in /usr/local/bin and the underlying machinery in

Now your ~/.bash_profile includes these lines (run this command to display the file: cat ~/.bash_profile):

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
export PATH

activate the new ~/.bash_profile:

source ~/.bash_profile


Never use python XYZ because then you’ll use the system default Python installation. Just use ./ XYZ

Install pip

chmod 700

Install virtualenv and virtualenvwrapper

sudo pip install virtualenv
(or if you want a certain version: sudo pip install virtualenv==1.7)

sudo pip install virtualenvwrapper

Now your ~/.bash_profile includes these lines:

source /usr/local/bin/

activate the new ~/.bash_profile:

source ~/.bash_profile

Create a virtualenv

mkvirtualenv -p python2.7 django5

python2.7 is the Python version used for this virtual environment. This is the syntax used by mkvirtualenv and will be interpreted correctly.

Useful commands for virtualenv

Display all installed libraries in your virtualenv:

Delete a virtualenv: rmvirtualenv django14
Work in a virtualenv: workon django15
Quit a virtualenv: deactivate

Create a project directory

Create a project directory and cd into it:

mkdir myfirstproject
cd myfirstproject

Clone a project

If you work an already existing project you can clone it now

git clone git@domain.tld:project.git

If you start a new project create the requirements.txt It might look like this:

-e hg+

Version number

We define the exact version number of every package but you can also just define the name so pip always picks the currently available version.
pip picks the most current version: Django
pip picks Django 1.5.1 even if there’s a newer version available: Django==1.5.1

Install Django

workon django15
pip install -r requirements.txt

If this error occurs just repeat the command until all packages are installed:

error: [Errno 54] Connection reset by peer

In the end you’ll get a status message like this:

Successfully installed Django Pillow PySimpleSOAP PyXML South Werkzeug argparse
cmsplugin-news cmsutils distribute django-ajax-filtered-fields django-appconf
django-appmedia django-classy-tags django-cms django-compressor django-cronjobs
django-extensions django-gmapi django-mptt django-navigation django-registration
django-reversion django-sekizai django-shorturls django-smart-selects django-tinymce
django-treemenus djangocms-utils fpconst geopy html5lib httpagentparser httplib2
icalendar ipython mock psycopg2 pygeocoder python-dateutil pytz rpc4django selenium
simplegeneric simplejson six sorl-thumbnail vobject wstools xlrd xlwt django-sendfile
django-tastypie mimeparse django-states

Cleaning up...


Some packages require that Django is already compiled. That’s why you might install them manually afterwards. Refere or create requirements.README where you document this.

To update your environment run this command:

pip install --upgrade -r requirements.txt

Install Homebrew

Homebrew has the advantages compared to MacPorts and Fink that its formulas stay fresh, it’s simple and it does not deliver precompiled applications (which might hang on your machine):

Ruby is shipped with OS X. You can now run this command like explained on the Homebrew homepage:

ruby -e "$(curl -fsSL"

Brewing knowledge

List all installed formulas: brew list --versions
Information about a formula: brew info postgresql
Attention: This command also delivers information on formulas not installed yet!

run brew update to get the newest versions of the formulas. The newest index will be downloaded.

Basically git is being used as the package database. That’s pretty smart.

brew versions postgis
brew search postgis

In order to activate the versions repository, you need to tap it:
brew tap homebrew/versions

brew install postgis15
brew link postgis15

Diagnose problems: brew doctor

Install PostgreSQL

PostgreSQL configuration files reside here:

PostgreSQL Client Authentication Configuration File: /usr/local/var/postgres/pg_hba.conf
PostgreSQL configuration file: /usr/local/var/postgres/postgresql.conf

We use the GUI pgAdmin to administrate PostgreSQL databases.


PostgreSQL 9.1 and 9.1.2 have a bug:

DatabaseError: invalid byte sequence for encoding “UTF8”: 0x00 bei Postgres 9.1:

Apply this fix:

Change this setting in /usr/local/var/postgres/postgresql.conf

standard_conforming_strings = off

brew install postgresql

Not needed necessarily (?):

Error: You must `brew link ossp-uuid' before postgresql can be installed
( brew link ossp-uuid )
(    Linking /usr/local/Cellar/ossp-uuid/1.6.2... 0 symlinks created )

Default PostgreSQL shipped with OS X

In OS X Lion PostgreSQL 9.0.4 was included for the first time: It’s used as the datastore for the stuff serveradmin(8) works on, Server.App and Server Essentials. But oh yes, you have it on the client, Server.App activates the stuff, does not install it.

So your desktop version of OS X doesn’t actually need it. Only if you upgrade to OS X server version it will be used. It seemes though that iMessage also uses PostgreSQL. TODO: Is that true?

Setting the proper path for PostgreSQL

We have two options and chose the first:

  1. Reroute the path to our own PostgreSQL.

    Downside: the OS might require just exactely the installed programs in that path. So that might be a problem down the road.

    If you run which psql and the result is /usr/bin/psql then the path leads to the original PostgreSQL version OS X shipped. To reroute it to the version Homebrew installed edit your ~/.bash_profile:

    export PATH=/usr/local/bin:$PATH

    Don’t forget to activate your ~/.bash_profile:

    source ~/.bash_profile

    If you run which psql again with this result everything is fine then: /usr/local/bin/psql

  2. Replacing the default version of PostgreSQL the OS shipped (as it is not being used by the OS at the moment) with our own (incl. custom extensions)

    For replacing the default PostgreSQL version with your own there’s this script:

    deactivate your ~/.bash_profile temporarily

    mv ~/.bash_profile ~/.bash_profile-orig

    Open a new terminal window and run

    curl | sh

    Reactivate your ~/.bash_profile

    mv ~/.bash_profile-orig ~/.bash_profile
    source ~/.bash_profile

    Afterwards these directories exist:


    Rerun this procedure after an OS X update

    • After an update of OS X you might have to run this procedure again as OS X might overwrite PostgreSQL in /usr/bin/
    • OS X might also overwrite /etc/sysctl.conf upon an OS X update so you’ll have to check whether it still contains the correct values.
    • You might also have to reinstall PostGIS Please see the section Upgrade OS X.

Initialize the database


Run this command only once upon initial installation.

If you install a new major version of PostgreSQL later on you can also upgrade your database files. Please refer to the section Upgrade OS X.

When you run the command

initdb /usr/local/var/postgres

the directory /usr/local/var/postgres/ will be created with the file postgresql.conf and the subdirectory base where PostgreSQL stores the database.

Run these commands to autorun PostgreSQL when OS X fires up:

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Install GeoDjango

Now install all the additional GeoDjango stuff:

brew install geos
brew install proj
brew install postgis15

If you run the command ./ migrate and get this error you probably have installed a new version of PostGIS but didn’t migrate your database yet:

  File "/Users/phil/PythonEnvs/django131/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/", line 44, in execute
    return self.cursor.execute(query, args)
django.db.utils.DatabaseError: function addgeometrycolumn(unknown, unknown, integer, unknown, integer) is not unique
LINE 1: SELECT AddGeometryColumn('main_userprofile', 'pnt_public', 4...
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.


If you run into this error message unable to execute gcc-4.2: No such file or directory run these commands:

brew install postgis --use-llvm
brew install postgis --use-gcc
brew install postgres --use-gcc=/usr/bin/gcc

(old: sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2)

gdal is not required - so you can ignore these commands:

(brew install gfortran)
(pip install numpy)

brew install gdal

Additional infos:

If you run psql without a database name as an option, it tries to connect to a database with the same name as the $USER psql runs as. So if you run it as user “postgres”, and a db with that name does not exist (yet), it will complain. You should first create a database using createdb somename and then connect with psql somename Note you can get a list of available databases with psql -l

Create the template spatial database:

createdb -E UTF8 template_postgis

Adding PLPGSQL language support:

createlang -d template_postgis plpgsql

psql -d postgres -c "UPDATE pg_database SET datistemplate='true'
  WHERE datname='template_postgis';"

psql -d template_postgis -f /usr/local/Cellar/postgis15/1.5.3/share/postgis/postgis.sql

psql -d template_postgis -f

Enabling users to alter spatial tables:

psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"

Create your own database

Create the database for your project using the just created template:

createdb -T template_postgis NAME-DES-PROJEKTES

TODO: andere Fehlermeldung hier oder:

If you now run psql on the comman line the error psql: FATAL:  database "DEIN-OS-X-USERNAME" does not exist will pop up. That’s why we now create it:

createuser -s YOUR-OS-X-USERNAME

Then the we’ll have to create the database:

createdb -T template_postgis DEIN-OS-X-USERNAME

Otherwise this error will occur psql: FATAL:  database "DEIN-OS-X-USERNAME" does not exist

Then you can run psql without providing a password.

Tune PostgreSQL

Create the file /etc/sysctl.conf with this content:


Edit the file /usr/local/var/postgres/postgresql.conf:

shared_buffers = 512MB
fsync = off
checkpoint_segments = 15
checkpoint_completion_target = 0.9

standard_conforming_strings = off # because of the bug

Additional Infos:

Does PostgreSQL run?

ps aux --forest
ps auxw | grep post

it should display something like this:

phil             280   0,6  0,0  2441664   1288   ??  Ss   Fr11pm    1:01.92 postgres: stats collector process
phil             279   0,1  0,0  3001012   3188   ??  Ss   Fr11pm    0:23.55 postgres: autovacuum launcher process
phil           25810   0,0  0,1  3001268   5996   ??  Ss    4:53pm   0:00.22 postgres: phil caruso_dev ::1(61804) idle
phil           24371   0,0  0,1  2537192  11880   ??  Ss   Mo03pm    0:02.47 /System/Library/PrivateFrameworks/DiskImages.framework/Resources/diskimages-helper -uuid B53B89F3-961A-404C-B23A-BF273AD57912 -post-exec 4
phil            1316   0,0  0,2  3005620  13136   ??  Ss   Sa12am    0:00.30 postgres: phil caruso_dev ::1(50436) idle
phil            1315   0,0  0,1  3002164   6672   ??  Ss   Sa12am    0:00.17 postgres: phil postgres ::1(50435) idle
phil             278   0,0  0,2  3000884  16956   ??  Ss   Fr11pm    0:13.29 postgres: wal writer process
phil             277   0,0  0,2  3000884  12944   ??  Rs   Fr11pm    0:20.79 postgres: writer process
phil             254   0,0  0,4  3000624  33576   ??  S    Fr11pm    0:06.80 /usr/local/Cellar/postgresql/9.1.2/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
phil           42772   0,0  0,0  2425480    188 s000  R+    4:18pm   0:00.00 grep post
phil           27056   0,0  0,1  3001268   5744   ??  Ss    5:43pm   0:00.12 postgres: phil caruso_dev ::1(63379) idle

Restart PostgresSQL:

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

After a restart of OS X the command sysctl kern.sysv.shmmax must return the value 1073741824.

Error handling

Open a new terminal window and monitor the logfile:

tail -f -n100 /usr/local/var/postgres/server.log

In order to log all SQl statements the configuration /usr/local/var/postgres/postgresql.conf has to be changed to include:

log_statement = 'all'

# Causes the duration of every completed statement to be logged.
# The default is off. Only superusers can change this setting.
log_duration = on

could not connect to server: No such file or directory (/tmp/.s.PGSQL.5432)

psql: could not connect to server: No such file or directory
 Is the server running locally and accepting
 connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

could not connect to server: No such file or directory (“/var/pgsql_socket/.s.PGSQL.5432)

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

Then you could probably run it like this: psql -h localhost

But: it’s a configuration problem:

In order to tell OS X to use your own installed programs you’ll have to properly set the path in your ~/.bash_profile See section Setting the proper path for PostgreSQL.

This error can also be detected by running brew doctor

It will report:

Error: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

FATAL: could not create shared memory segment: Invalid argument

FATAL:  could not create shared memory segment: Invalid argument
DETAIL:  Failed system call was shmget(key=5432001, size=572375040, 03600).
HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter.  You can either reduce the request size or reconfigure the kernel with larger SHMMAX.  To reduce the request size (currently 572375040 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
   If the request size is already small, it's possible that it is less than your kernel's SHMMIN parameter, in which case raising the request size or reconfiguring SHMMIN is called for.
   The PostgreSQL documentation contains more information about shared memory configuration.

then the values in /etc/sysctl.conf are not correct anymore.

FATAL: lock file “” already exists

FATAL:  lock file "" already exists
HINT:  Is another postmaster (PID 193) running in data directory "/usr/local/var/postgres"?
LOG:  database system was interrupted; last known up at 2012-10-15 22:50:22 CEST
LOG:  database system was not properly shut down; automatic recovery in progress

then simply remove this file:

sudo rm /usr/local/var/postgres/

ERROR: could not access file “$libdir/postgis-1.5”: No such file or directory

ERROR:  could not access file "$libdir/postgis-1.5": No such file or directory
STATEMENT:  SELECT postgis_lib_version()

then the default PostgreSQL shipped with OS X still leads to confusion. See the section Default PostgreSQL shipped with OS X.

could not connect to server: Connection refused

After starting the computer this error message appears when you run the command ./ runserver:

  File "/Users/phil/PythonEnvs/django131/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/", line 140, in _cursor
    self.connection = Database.connect(**conn_params)
psycopg2.OperationalError: could not connect to server: Connection refused
  Is the server running on host "localhost" and accepting
  TCP/IP connections on port 5432?
could not connect to server: Connection refused
  Is the server running on host "localhost" and accepting
  TCP/IP connections on port 5432?
could not connect to server: Connection refused
  Is the server running on host "localhost" and accepting
  TCP/IP connections on port 5432?

In this case just wait patiently - the PostgreSQL server just didn’t fire up yet. Retry after a little while.

launchctl: Dubious ownership on file (skipping)

After a cold shutdown of the computer this error message appears when running the command ./ runserver:

  File "/Users/phil/PythonEnvs/django131/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/", line 140, in _cursor
    self.connection = Database.connect(**conn_params)
psycopg2.OperationalError: could not connect to server: Connection refused
    Is the server running on host "localhost" and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" and accepting
    TCP/IP connections on port 5432?

Try it manually:

sudo launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist

launchctl: Dubious ownership on file (skipping): /Users/phil/Library/LaunchAgents/org.postgresql.postgres.plist
nothing found to load

Try to repair the file ownerships.

Install the PostgreSQL Adapter Psycopg2

If Psycopg2 is not yet installed via the requirements.txt then install it now:

sudo pip install psycopg2

Additional tools

brew install graphicsmagick
brew install gs
brew install gettext

If you run into this error and which gettext doesn’t return a result it’s not included in OS X:

==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

OS X provides the BSD gettext library and some software gets confused if both are in the library path.

Generally there are no consequences of this for you.
If you build your own software and it requires this formula, you'll need
to add its lib & include paths to your build variables:

  LDFLAGS: -L/usr/local/Cellar/gettext/
  CPPFLAGS: -I/usr/local/Cellar/gettext/
==> Summary
/usr/local/Cellar/gettext/ 358 files, 11M, built in 114 seconds

Set the paths manually:

ln -s /usr/local/Cellar/gettext/ /usr/local/bin/autopoint
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/envsubst
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/gettext
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/gettextize
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgattrib
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgcat
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgcmp
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgcomm
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgconv
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgen
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgexec
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgfilter
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgfmt
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msggrep
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msginit
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgmerge
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msgunfmt
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/msguniq
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/ngettext
ln -s /usr/local/Cellar/gettext/ /usr/local/bin/xgettext


We use and push the repo there as well. Just setup your public key here:

When committing to git we use such keywords to refer or close a ticket: fixed #123 oder see #123



We use some aliases like gpull, gpush, gcommit in the shell. See:

Development tools

pip install -E django15 django-extensions runserver_plus - The standard runserver stuff but with the Werkzeug debugger baked in. Requires Werkzeug. This one kicks ass.


Graphviz is open source graph visualization software

  1. Install:


    brew install graphviz

    Install the Python wrapper for graphviz:

    pip install pygraphviz
  2. Generate a .dot file:

    The .dot file is the illustration of the models as a graph:

    python graph_models name_of_application_here >
  3. Download and install Graphviz:

  4. Display the file:

    On OS X you can open the .dot file with (Linux: with dotty).

Scrum (Scrumdo - Agile Development Story Management Site)



Python IDE & Django IDE:


  1. Install the Node Package Manager:

    This package will install node and npm into /usr/local/bin

  2. Install less globally as root:

    sudo npm install -g less
  3. Setup your IDE so that it compiles the less files upon change. For PyCharm:

    Preferences... / File Watchers / + / LESS / PyCharm will locate the transpiler automatically - so you can accept the default values.

More infos on LESS

Upgrade OS X

Problems: The best way out is always through. (Robert Frost)

If the development environment should be repaired then all components installed via homebrew should be removed and freshly installed.

If OS X was setup and the migration assistant from a TimeMachine backup was used several things won’t properly run anymore.

  1. Upgrade OS X

  2. Update git and pgAdmin

  3. Update XCode via the App Store

    Reinstall the Command Line Tools: XCode Preferences / Downloads / Components / Command Line Tools (115,1 MB)

  4. Update Python:

    Will be installed here: /usr/local/bin/python and /Library/Frameworks/Python.framework/Versions/2.7/bin/python

    The default OS X Python resides here: /usr/bin/python

    If a message pops up that X11 is required you can install XQuartz:
  5. Install setuptools: Easily download, build, install, upgrade, and uninstall Python packages

    chmod 700
  6. (Re)install Pip:

    chmod 700
  7. (Re)install virtualenv and virtualenvwrapper:

    sudo pip uninstall virtualenv
    sudo pip uninstall virtualenvwrapper
    sudo pip install virtualenv (or sudo pip install virtualenv==1.7)
    sudo pip install virtualenvwrapper
  8. (Re)activate this section in ~/.bash_profile:

    export WORKON_HOME
    source /Library/Frameworks/Python.framework/Versions/2.7/bin/
    # Setting PATH for Python 2.7
    # The orginal version is saved in .bash_profile.pysave
    export PATH
  9. Activate the new ~/.bash_profile with source ~/.bash_profile

  10. (Re)create the virtualenvs with the new version Python of Python:

    rmvirtualenv django14
    sudo rm -rf /Users/<USERNAME>/PythonEnvs/django14
    mkvirtualenv -p python2.7 django15
    workon django15
    pip install -r requirements.txt
  11. Update homebrew

    Just rerun the installation command for homebrew: Install Homebrew

    Otherwise such errors may appear:

    curl: (6) Could not resolve host:; nodename nor servname provided, or not known
    Error: Failure while executing: /usr/bin/curl -f#LA Homebrew\ 0.8\ (Ruby\ 1.8.7-249;\ Mac\ OS\ X\ 10.7.2) -o /Users/phil/Library/Caches/Homebrew/postgresql-9.0.4.tar.bz2
  12. If PostGIS reports an error:

    django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "gemeinde-weiler".
    GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?


    brew remove --force postgis
    brew install postgis

    You’ll probably also have to delete the template database an recreate it. Bevore you do that you’ll have to set the template flag to False:

    psql -d postgres -c "UPDATE pg_database SET datistemplate='false' WHERE datname='template_postgis';"
    dropdb template_postgis
    droplang -d template_postgis plpgsql
  13. Update PostgreSQL:

    To migrate to another major PostgreSQL version do this for all of your databases:

    pg_dump DBNAME -f dbdump.sql

    Then install the new PostgreSQL version:

    brew uninstall postgresql
    brew install postgresql

    Please see the section Setting the proper path for PostgreSQL.


    If you upgrade to another major PostgreSQL version the database format might not be compatible anymore!

    These errors might occur:

    FATAL: database files are incompatible with server
    DETAIL: The data directory was initialized by PostgreSQL version 9.0, which is not compatible with this version 9.1.2.

    We have already created a dump file dbdump.sql so we can re-initialize the database now:

    mv /usr/local/var/postgres postgres-9.0
    initdb /usr/local/var/postgres
    cp /usr/local/Cellar/postgresql/9.1.2/org.postgresql.postgres.plist
    launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist

    After installing the new PostgreSQL version re-create your databases and load the dump data files into the databases:

    psql DBNAME < dbdump.sql

    You could also use pg_upgrade within minor PostgreSQL versions but this seemes to be a little buggy sometimes.

    pg_upgrade -b /usr/local/bin/archive/ -B /usr/local/bin/ -d /usr/local/var/postgres-9.0 -D /usr/local/var/postgres -l ~/pg_upgrade.log

    Edit the file /usr/local/var/postgres/postgresql.conf. See: Tune PostgreSQL

[1]How to open apps from an unidentified developer in OS X Mountain Lion: