Vao Tsun
Vao Tsun

Reputation: 51406

Postgres - Peer authentication - psql: FATAL: role "xxxx" does not exist

I know there are plenty of posts with close message. I've read hopefully all. And did not find the answer. Some offer to use -h localhost to jump from local to host rules in hba.conf. Some say to set trust on local... But I want peer authentication, not over TCP and not trusted!

so I have user vao on both OS AND DB:

t=# \! who am i
vao      pts/8        2016-11-11 12:23 (10.1.10.158)

t=# \du+ vao
                  List of roles
 Role name | Attributes | Member of | Description
-----------+------------+-----------+-------------
 vao       | Superuser  | {}        |

and yet when I try to psql I get error:

$ psql t
psql: FATAL:  role "vao" does not exist

According to docs

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping). This method is only supported on local connections.

and

Peer authentication is only available on operating systems providing the getpeereid() function, the SO_PEERCRED socket parameter, or similar mechanisms. Currently that includes Linux, most flavors of BSD including OS X, and Solaris.

So I look if Debian supports getpeereid() or SO_PEERCRED and desperately dig for explanation.

Until I realyze I hit obvious lack of environment set. If psql doesn't find user, maybe it doesn't find a socket?.. So I check unix_socket_directories in postgresql.conf and according to psql manual:

--host=hostname Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix-domain socket.

try psql t -h '/path/to/unix_socket_directories' and voila - I'm there

And this is not the first time I step on this rake! So I post it here - hope it will help somebody.

Upvotes: 2

Views: 800

Answers (1)

Vao Tsun
Vao Tsun

Reputation: 51406

The error is misleading.

instead of

psql: FATAL: role "xxx" does not exist

should be

psql: FATAL: socket "yyy" does not exist

or anything else, that would lead us to the idea, that the we lack Environment Variables

so smth like export PGHOST=/var/run/postgresql will cure the ilness

Upvotes: 1

Related Questions