7 de febrero de 2012

Repairing PostgreSQL after upgrading to Mac OSX Lion

I upgraded to Mac OSX to 10.7.3 (Lion) yesterday and had some issues with PostgreSQL.

For instance, when I tried to run the South migrations for the Django project I'm working at, I got this:

psycopg2.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"?
How I fixed this?

  1.  Edit PostgreSQL's config to define the unix_socket_directory setting:

    $ sudo nano /Library/PostgreSQL/9.0/data/postgresql.conf

    In my case I changed the setting to unix_socket_directory = '/var/pgsql_socket/'.
  2. Exceute the following commands:

    $ sudo dscl . append /Groups/_postgres GroupMembership postgres
    $ sudo chmod g+w,o+rx /var/pgsql_socket/

  3.  Restart the server:

    $ sudo -u postgres /Library/PostgreSQL/9.0/bin/pg_ctl -D /Library/PostgreSQL/9.0/data/ restart
Note: You may want to add an alias for this command in your ~/.profile file. If so, it is just a matter of adding a line like this:

alias restart_postgres='sudo -u postgres /Library/PostgreSQL/9.0/bin/pg_ctl -D /Library/PostgreSQL/9.0/data/ restart'

No hay comentarios: