I just started playing around with PostgreSQL. My goal is to create a new user outside of postgres with all of the same privileges and create a database for my ror app. I’m able to login under postgres. I did create an user named Jason, which is good, however when I do sudo -u username psql I receive the following error…
sudo: unknown user: Jason
sudo: unable to initialize policy plugin
I can determine that the username exists by checking both \dg in my postgres console.
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
Jason | Superuser, Create role, Create DB, Replication | {}
postgres | Superuser, Create role, Create DB, Replication | {}
What’s causing this problem? Also, I checked my local pg_hba.conf and have what I believe to be the correct settings.
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
You are confusing system user with database user. The error message comes from
sudoand has nothing to do with PostgreSQL at all.To log in as database user Jason:
You need to supply a password, of course, as long as password-less access is not set up. Peer authentication only works for a system user of the same name (“Jason”).
More in the excellent manual about
psqlhere and about authentication methods here.