Rajat
Rajat

Reputation: 105

Ruby on Rails Authentication Error for postgres

I have created Postgresql database locally. Postgre database

And here is my database.yml file. default: &default adapter: postgresql pool: 5 timeout: 5000

development:
  <<: *default
  database: myrubyblog
  username: postgres
  password: Naruto1994.

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: myrubyblog
  username: postgres
  password: Naruto1994.

production:
  <<: *default
  database: myrubyblog
  username: postgres
  password: Naruto1994.

I have made sure to enter correct password but I am still getting this error.

Error in the code

Upvotes: 3

Views: 884

Answers (3)

Oscar Luza
Oscar Luza

Reputation: 404

You just need to add host: localhost to each env. e.g.

development:
  <<: *default
  database: myrubyblog
  host: localhost
  username: postgres
  password: Naruto1994.

Upvotes: 1

kansiho
kansiho

Reputation: 532

Messages like this indicate that you contacted the server, and it is willing to talk to you, but not until you pass the authorization method specified in the pg_hba.conf file.

Try this:

// set new password for user "postgres"
$sudo su postgres -c 'psql --username=postgres'
ALTER USER postgres with encrypted password 'your_password';
//change pg_hba.conf
local all postgres md5

then restart postgres.

This article might help you: Postgresql: password authentication failed for user "postgres"

Upvotes: 3

widjajayd
widjajayd

Reputation: 6253

you may add localhost, and makesure if you have password with dot or no dot (Naruto1994), and my suggestion split database name between each environment (development, test and production)

development:
  adapter: postgresql
  encoding: unicode
  database: myrubyblog_development
  host: localhost
  username: postgres
  password: Naruto1994.  
  pool: 5

test: 
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: myrubyblog_test
  username: postgres
  password: Naruto1994.  
  pool: 5

production:
  adapter: postgresql
  encoding: unicode
  database: myrubyblog_production
  pool: 5
  host: localhost
  username: #env_variable
  password: #env_variable

Upvotes: 2

Related Questions