ruby on rails致命错误(用户****密码身份验证失败)

carvr3hs  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(414)

对不起,我英语不好
当我尝试运行本地服务器时,rails给了我以下问题:

ActiveRecord :: ConnectionNotEstablished: FATAL: failed password authentication for user "Blog"

Caused by:
PG :: ConnectionBad: FATAL: failed authentication with password for user "Blog"

但我的密码和用户名都是正确的。
这是我的yaml文件

default: &default
  adapter: postgresql
  encoding: unicode

development:
  <<: *default
  database: Blog_development
  encoding: UTF-8
  username: Blog
  password: Giungla
  host: localhost
  port: 5432

test:
  <<: *default
  database: Blog_test

production:
  <<: *default
  database: Blog_production
  username: Blog
  password: <%= ENV['BLOG_DATABASE_PASSWORD'] %>

我终端机里的痕迹


**rails db:migrate --trace
**Invoke db:migrate (first_time)
**Invoke db:load_config (first_time)
**Invoke environment (first_time)   
**Execute environment
**Execute db:load_config
**Execute db:migrate

rails aborted!
ActiveRecord::ConnectionNotEstablished: FATALE:  autenticazione con password fallita per l'utente "Blog"
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:83:in `rescue in new_client'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_handling.rb:283:in `connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/railties/databases.rake:90:in `each'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/command.rb:50:in `invoke'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands.rb:18:in `<main>'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
bin/rails:4:in `<main>'

Caused by:
PG::ConnectionBad: FATALE:  autenticazione con password fallita per l'utente "Blog"
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/pg-1.2.3-x64-mingw32/lib/pg.rb:58:in `initialize'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/pg-1.2.3-x64-mingw32/lib/pg.rb:58:in `new'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/pg-1.2.3-x64-mingw32/lib/pg.rb:58:in `connect'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/connection_handling.rb:283:in `connection'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/railties/databases.rake:90:in `each'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/command.rb:50:in `invoke'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands.rb:18:in `<main>'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate**

我如何解决这个问题?我是rails新手,我正在努力学习,但现在我被卡住了

hmae6n7t

hmae6n7t1#

因此,您的数据库配置被正确使用,因为您的错误消息提到了它试图使用的用户名。我认为rails中的数据库配置没有任何问题,我认为问题可能在于postgres配置不匹配。
我会尝试使用postgres cli客户端或您喜欢的任何gui数据库客户端连接到数据库。使用与rails配置中相同的凭据,看看是否可以得到相同的错误。
您是如何在postgres数据库中创建此用户的?如果您有sql语句,可以方便地提供更多细节。
跑步 rails db:create 可能是运行的第一个命令,以确保没有任何与迁移相关的东西会使事情复杂化。我希望您会收到与该命令相同的错误消息。
另外,这个命令使用什么rails环境(例如开发或生产)。请注意,生产数据库配置使用env变量 BLOG_DATABASE_PASSWORD 运行rails命令时,可能不会在shell中设置。在一个命令中测试这一点的最简单方法是:

$ BLOG_DATABASE_PASSWORD=Giungla rails db:migrate

当然,您可能希望生产数据库密码与开发数据库密码不同,这只是一个示例。
我希望这里有些东西能帮你解决它!

相关问题