Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: su - Authentication failure in postgresql

I have installed PostgreSQL 10.6, Postgres client and Pgadmin 4.

I just created a new Rails application and I used Postgresql as the database for the application, only for me to get a message saying

su: Authentication Failure

each time I try to login into the postgres account to create the development database for the rails application.

I have tried a couple of times to fix this issue, I have also attempted to solve by trying out several solutions that I found online, but all to no avail.

What should I do? I need some assistance.

like image 950
Promise Preston Avatar asked Mar 15 '19 16:03

Promise Preston


People also ask

How do I fix Postgres password authentication failed?

Restart the PostgreSQL service from the Services control panel ( start->run->services. msc ) Connect using psql or pgAdmin4 or whatever you prefer. Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

How do I authenticate a user in PostgreSQL?

PostgreSQL supports GSSAPI with Kerberos authentication according to RFC 1964. GSSAPI provides automatic authentication (single sign-on) for systems that support it. The authentication itself is secure, but the data sent over the database connection will be sent unencrypted unless SSL is used.


1 Answers

To solve this simply follow the solution below

Change the password for a user

Login to the server where PostgreSQL is installed.

Next, switch to the root user:

sudo su -

Log in to psql using the postgres database login role, connecting to the postgres database:

psql postgres postgres

Issue the \password command to alter the password of the user:

\password my-user

Note: This will prompt you to enter a new password twice.

And then exit the psql prompt:

\q 

Afterwhich you can exit and then test the password using the command below to login to the postgres database:

psql -U my-user -W postgres

Change the password for the postgres user

If you do not know the password for the postgres user, run the psql command from the postgres user account:

sudo passwd postgres

Note: This will prompt you to enter a new password twice.

And then exit the psql prompt:

\q 

To test and confirm the password change or setup, run the psql command from the postgres user account:

su - postgres

Enter the new password that you just setup.

That's all

I hope this helps.

like image 151
Promise Preston Avatar answered Nov 03 '22 18:11

Promise Preston