Login Failed with Existing User on PostgreSQL

13,459

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.

Share:
13,459

Related videos on Youtube

thank_you
Author by

thank_you

Updated on September 15, 2022

Comments

  • thank_you
    thank_you over 1 year

    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
    
  • thank_you
    thank_you over 11 years
    Now I'm receiving this error... psql: FATAL: Peer authentication failed for user "Jason"
  • thank_you
    thank_you over 11 years
    I was able to login, but now I need to change the password for Jason since it doesn't work. Thanks for the help and the correct answer!