Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login Failed with Existing User on PostgreSQL

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
like image 424
thank_you Avatar asked Oct 22 '12 02:10

thank_you


People also ask

What is peer and MD5 in PostgreSQL?

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.

How do I grant superuser permissions to postgres user?

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.


1 Answers

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.

like image 131
Erwin Brandstetter Avatar answered Oct 05 '22 14:10

Erwin Brandstetter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!