Reputation: 10969
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?
Upvotes: 11
Views: 13505
Reputation: 259
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
Upvotes: 11
Reputation: 689
As other answers addressed other alternatives, I guess I could provide something about Mac OS X Server on Lion. I run into very similar issue - in my case even -h localhost
didn't work as networking was disabled in PostregSQL which is by the way in many cases very good idea. The thing with Mac OS X Server is that it launches PostgreSQL server via launchd
.
Some hints as you go around:
serveradmin
service: postgres
launchd
configuration file: /System/Library/LaunchDaemons/org.postgresql.postgres.plist
/var/pgsql
/var/pgsql_socket
That configuration file overrides several configuration directives that can be found in postgresql.conf
under database folder. Especially these two:
unix_socket_group
unix_socket_permissions
You can find that _postgres
account is used to run the server and everything is also accessible if active user is member of _postgres
group.
By running dscl . -read /Groups/_postgres GroupMembership
you can see that by default that group has these members: _devicemgr
_calendar
_teamsserver
_www
I guess you have two options. Add yourself to _postgres group or change launchd
configuration plist file. The later is just plain text editing... But beware of security, because this way you'll be opening Server to whatever meets criteria you change (see the last paragraph).
The former can be done either via Server.app
or via dscl
command-line utility. The first option probably doesn't need anything to be added. Just make sure that you can see System Accounts (View -> Hide/Show System Accounts). I'm kind of CLI junkie so this should add your user to _postgres
group:
sudo dscl . -append /Groups/_postgres GroupMembership $USER
Of course you should be careful what you run under your account then because you're giving access to you Mac OS X Server database back-end. So either secure you _postgres
account or create separate user to manipulate your database or don't save anything private there.
Upvotes: 1
Reputation: 303451
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.
Upvotes: 2
Reputation: 44250
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/
Upvotes: 6