Postgresql: Why should I specify -h localhost when starting psql?

psql mydb gives:

 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 fine. pg_hba.conf as follows:

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

What?

+6
source share
5 answers

I had the same thing with me, presumably due to the conflicting version of psql (one from Lion, one from homegrown). Although I still haven't been able to figure out how to get psql to use the / tmp socket directory, I have work to do.

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

 export PGHOST=/tmp 

This sets the correct "host" back to the correct socket directory without setting the -h flag

+8
source

This seems to be a reported defect .

+2
source

Possibly psql and the server use a different location for the unix-domain socket. (/ var / pgsql_socket / is a strange place) This can happen if you mix binary files from different packages. Try to find the socket (/ tmp / is a good place to start). You can force psql to use a different directory by overusing the -h option:

 psql -h /tmp/ 
+2
source

This happened to me in OS X, and the problem was that /usr/bin/psql is what I used, but postmaster works from /Library/PostgreSQL/9.0 . Using /Library/PostgreSQL/9.0/bin/psql (getting this in my PATH for everything else) fixed the problem.

+2
source

Since the other answers related to other alternatives, I assume I can provide something about Mac OS X Server on Lion. I ran into very similar problems - in my case, even -h localhost did not work, because PostregSQL had a network disconnected, which, by the way, is in many cases a very good idea. The thing about Mac OS X Server is that it launches the PostgreSQL server through launchd .

Some tips when you go:

  • serveradmin service: postgres
  • launchd configuration file: /System/Library/LaunchDaemons/org.postgresql.postgres.plist
  • database folder: /var/pgsql
  • sockets folder: /var/pgsql_socket

This configuration file overrides several configuration directives that can be found in postgresql.conf in the database folder. Especially these two:

  • unix_socket_group
  • unix_socket_permissions

You may find that the _postgres account is used to start the server, and all this is also available if the active user is a member of the _postgres group.

By running dscl . -read /Groups/_postgres GroupMembership dscl . -read /Groups/_postgres GroupMembership , you will see that by default this group has the following elements: _devicemgr _calendar _teamsserver _www

I think you have two options. Add yourself to the _postgres group or modify the t21> configuration file. Later it is just text editing ... But be careful with security, because in this way you open Server for what meets the criteria that you change (see the last paragraph).

The first can be done either through Server.app or through the Server.app command-line dscl . The first option probably does not need to be added. Just make sure you see the system accounts (View → Hide / Show System Accounts). I'm kind of a CLI junkie, so this should add your user to the _postgres group:

 sudo dscl . -append /Groups/_postgres GroupMembership $USER 

Of course, you should be careful what you run under your account, because you provide access to the Mac OS X Server database database. Thus, either secure your _postgres account, or create a separate user to manage your database or do not save anything private there.

+1
source

Source: https://habr.com/ru/post/897029/


All Articles