Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql: Why do I have to specify -h localhost when running psql?

psql mydb yields:

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

psql -h localhost mydb works just fine. pg_hba.conf looks like:

local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust

What up?

like image 821
Wells Avatar asked Sep 10 '11 02:09

Wells


4 Answers

I had the exact same thing happen to me, presumably due to the conflicting version of psql (one from Lion, one from homebrew). While I still haven't been able to figure out how to make psql use the /tmp socket directory, I do have a work around.

Put the following in your .bashrc (or .zshrc, etc):

export PGHOST=/tmp

This sets the correct "host" back to the correct socket directory, without having to supply the -h flag

like image 134
joshuadavey Avatar answered Oct 17 '22 10:10

joshuadavey


Probably psql and the server use a different location for the unix-domain socket. ( /var/pgsql_socket/ is a strange location) This can happen if you are mixing binaries from different packages. Try to locate the socket ( /tmp/ is a good place to start) You can force psql to use a different directory by misusing the -h option:

psql -h /tmp/
like image 35
wildplasser Avatar answered Oct 17 '22 12:10

wildplasser


It appears to be a reported defect.

like image 34
Oh Chin Boon Avatar answered Oct 17 '22 10:10

Oh Chin Boon


This happened to me on OS X, and the problem was that /usr/bin/psql is what I was using, but postmaster was running from /Library/PostgreSQL/9.0. Using /Library/PostgreSQL/9.0/bin/psql (getting that into my PATH before all else) fixed the problem.

like image 2
Phrogz Avatar answered Oct 17 '22 12:10

Phrogz