PostgreSQL 9.1.2 via homebrew on OS X 10.7.2

Published on Dec. 22, 2011, 12:20 a.m.

django homebrew osx postgresql python

I just picked up a snazzy new Macbook Air, and I'm working on setting up my development environment(s). For the most part this has been fairly easy. I pull in my repos from github and bitbucket, and I use virtualenv and pip to organize all my python packages (mostly installing from requirements files). Most of the other command-line tools get intalled with homebrew, and this time around I decided to install PostgreSQL with homebrew.

I didn't keep track of all the steps I followed, but I'm pretty sure I just kept all the defaults while installing. I set up a new database cluster with initdb and then I created a local user (no password) and set up a database for one of my Django apps. But then I got this error when running syncdb:

OperationalError: could not connect to server: Permission denied
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

That's odd. I did some digging and didn't really find much info that seem relevant (though there is this ticket: https://trac.macports.org/ticket/30125). However, when I explicitly specified a HOST value in my django settings, things just started working.

DATABASES = { 
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'somedb',  
        'USER': 'someuser', 
        'PASSWORD': '', 
        'HOST': 'localhost',
        'PORT': '', 
    }   
}

I'm not quite sure what's going on here, or if this is a bug in PostgreSQL. Other than that little snag, everything seems to be working swell.

Apparently reinstalling psycopg2 also fixes this problem:

pip install -U psycopg2

Thanks to @lukeman for the tip, and to @dstufft who helped him!

:)

comments powered by Disqus