0

I have tried to set the postgresql username from both the linux console as well as within Postgresql using the \password command. However, in my rails database, the only password that is working is password and I'm not sure where this is set up.

Prior to making this new server available on the Internet, I just wanted to change a working password to one that is more complicated. Not quite sure what's going on here though.

Here's what happens when I run rake db:migrate:status

# rake db:migrate:status
rake aborted!
PG::ConnectionBad: FATAL:  Peer authentication failed for user "postgres"
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/schema_migration.rb:22:in `table_exists?'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:124:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:migrate:status
(See full trace by running task with --trace)

Again, I have changed the password in postgresql as well from what I can see:

# su postgres
postgres@a17924e746f0:/$ psql
psql (10.7 (Ubuntu 10.7-0ubuntu0.18.04.1))
Type "help" for help.

postgres=# \quit
postgres@a17924e746f0:/$ psql postgres postgres
psql (10.7 (Ubuntu 10.7-0ubuntu0.18.04.1))
Type "help" for help.

postgres=# \password
Enter new password:
Enter it again:
postgres=# \quit

and changed it from within Linux too:

# passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Any suggestions would be greatly appreciated.

LewlSauce
  • 5,326
  • 8
  • 44
  • 91
  • Check config/database.yml there should be configuration of your database – noname Aug 13 '19 at 12:22
  • Hi @noname, the configuration in the `config/database.yml` file uses `password` for the postgres user password. I'm trying to change this password, but I have no idea how. When I change the password from the command line and within postgresql, the new password doesn't work when I try to check the database from within rails. – LewlSauce Aug 13 '19 at 12:25
  • so make sure that, your credentials in configurations and in database are the same. When you changing it for database you have to change for config as well, cause your rails app do not know how to login if you not change password for app. – noname Aug 13 '19 at 12:30
  • @noname that's exactly what I'm doing. I'm changing the password on both the CLI, the database, and the database.yml file, all matching. I'm simply even trying changing the password to just `password1` just for testing and it still says authentication failed. – LewlSauce Aug 13 '19 at 12:31
  • In here you have answer https://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge – noname Aug 13 '19 at 12:33
  • 1
    I am glad I could help. – noname Aug 13 '19 at 12:36

0 Answers0