Postgresql – Running postgresql in Mac Terminal

mac os xpostgresql

I have a production SQL dump file that I want to restore to my local psql db for debugging reasons.

I can't access psql via the terminal though pgAdmin3 works just fine. Here is the error I'm getting:

$ psql
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"?

$ locate psql | grep /bin
/Library/PostgreSQL/9.0/bin/psql
/Library/PostgreSQL/versions/9.0.1/bin/psql
/opt/local/bin/psql83
/opt/local/lib/postgresql83/bin/psql
/usr/bin/psql

I tried using sudo, no change. Any Idea why I can't connect w terminal on the mac and then restore the sql db dump locally?

Thanks

Best Answer

Try specifying -h localhost as a psql parameter, to connect via tcp/ip rather than a unix socket.

Likely, your psql and postgresql have different ideas of the correct setting for unix_socket_directory. Especially seeing as you have at least two different builds of postgresql installed! You might want to make sure you're using the psql client that corresponds to your postgresql server, since they have different major versions that will have other benefits too. Failing that, you can give a unix socket directory name as the hostname, e.g. psql -h /tmp will look for /tmp/.s.PGSQL.5342.