Fix Postgres permission denied issue on OSX Lion

The good thing is that Apple decides to bundle PostgresSQL 8.4 with OSX Lion which cause conflict if you install Postgres 9.x using brew or Macport. You will likely bump into following error:

    $ psql -d postgres -U postgres
    psql: 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"? 

So what’s going wrong here? Because the stock postgresql has higher precedence in PATH.

To fix this, simply make /usr/local/bin highest precendence for $PATH.

Local scope (recommended):
Edit ~/.bash_profile

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

System-wide scope:
Edit your /etc/paths and move your /usr/local/bin to the top.

$ sudo nano /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

About Jones Lee

Nothing much about me..

Leave a comment