2

This is my database.yml:

development:
  adapter: postgresql
  database: myUsername
  username: myUsername
  password: myPassword
  host: localhost

So, when I go to my local page, no errors are shown. If I change password in database.yml to something incorrect, I get

PG::ConnectionBad: FATAL: password authentication failed for user "myUsername" FATAL: password authentication failed for user "myUsername"

error. Therefore, my password is right.

But still, when I run

rake db:migrate

I get errors no matter if my password is right or wrong. If it's right, I get the following error:

PG::ConnectionBad: fe_sendauth: no password supplied

If it's wrong, I get the same error as on my local page:

PG::ConnectionBad: FATAL: password authentication failed for user "myUsername" FATAL: password authentication failed for user "myUsername"

What causes it to think that correct password is "not supplied"? Please, any help or information is appreciated, I've been messing with it for two days now.

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Evgenia Karunus
  • 10,715
  • 5
  • 56
  • 70

2 Answers2

0
  1. edit pg_hba.conf via gedit as root user by changing md5 for trust, see here empty, uneditable pg_hba.conf file for some issues that may arise
  2. sudo service postgresql restart
  3. restart your local server

Provided your password matches username, this should work.

Community
  • 1
  • 1
Evgenia Karunus
  • 10,715
  • 5
  • 56
  • 70
0

There are two steps to allow connections to PostgreSQL:

  1. Set a password for the postgres user
  2. Change the password for the postgres user

1. Setting a password for the postgres user

On Linux systems, there is no default password set.

To set the default password:

Run the psql command from the postgres user account:

sudo -u postgres psql postgres

Set the password:

\password postgres

Enter a password.

Close psql.

\q

After this, we will change the password for the postgres user in step 2

N/B: Step 2 is very important, else you will still have the same Authenticate Failure issue.

2. Change the password for the postgres user

If you do not know the password for the User

Run the psql command from the postgres user account:

sudo passwd postgres

Enter a password.

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.

To exit the postgreql environment, simply type the command below

exit

That's all.

If after these steps, you experience an issue like the one below

Postgresql: FATAL: role does not exist

simply follow the answer here in this link (Answer: Postgresql: FATAL: role does not exist) to fix the issue.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143