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
peer means it will trust the identity (authenticity) of UNIX user. So not asking for a password. md5 means it will always ask for a password, and validate it after hashing with MD5 . trust means it will never ask for a password, and always trust any connection.
Log into PostgreSQL and run the following ALTER USER command to change user test_user to superuser. Replace test_user with username as per your requirement. postgres-# ALTER USER test_user WITH SUPERUSER; In the above command, we use WITH SUPERUSER clause to change user to superuser.
You are confusing system user with database user. The error message comes from sudo and has nothing to do with PostgreSQL at all.
To log in as database user Jason:
psql -U 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 psql here and about authentication methods here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With