简体   繁体   English

Rails:致命:用户密码验证失败

[英]Rails: FATAL: Password Authentication Failed For User

I'm having an issue connecting my Postgres database.我在连接 Postgres 数据库时遇到问题。 I created a user for it (it never prompted me for a password), so I ran the command ALTER USER user_name WITH PASSWORD password to create one.我为它创建了一个用户(它从不提示我输入密码),所以我运行命令ALTER USER user_name WITH PASSWORD password来创建一个。 I set the user and password in my database.yml file in my config directory for my Rails project.我在我的 Rails 项目的 config 目录中的database.yml文件中设置了用户和密码。 It's still telling me that I have an authentication failure (like my title) and I have no idea why.它仍然告诉我我的身份验证失败(如我的头衔),我不知道为什么。 I modified my pg_hba.conf file from this answer from this link .我从这个链接的这个答案修改了我的pg_hba.conf文件。 The only thing I can think of that would solve this issue is making my user a superuser.我能想到的唯一能解决这个问题的方法就是让我的用户成为超级用户。 But I'd like to know why this isn't working right now without making it a superuser.但我想知道为什么如果不让它成为超级用户,这现在不起作用。 Anyone have any idea?任何人有任何想法?

Edit:编辑:

=> Booting Thin
=> Rails 3.2.11 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': FATAL:  password authentication failed for user "crowdcode" (PG::Error)
FATAL:  password authentication failed for user "crowdcode"
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:308:in `clear_cache!'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:418:in `_run__898392718112352949__prepare__1631078305261036285__callbacks'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/ubuntu/Git/crowdcode/config/environment.rb:5:in `<top (required)>'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
    from /home/ubuntu/Git/crowdcode/config.ru:3:in `block in <main>'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
    from /home/ubuntu/Git/crowdcode/config.ru:in `new'
    from /home/ubuntu/Git/crowdcode/config.ru:in `<main>'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/server.rb:46:in `app'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/server.rb:70:in `start'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in `tap'
    from /home/ubuntu/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
  1. make you user superuser: ALTER USER user_name WITH SUPERUSER;让你成为超级用户:ALTER USER user_name WITH SUPERUSER;

  2. edit the file pg_hba.conf : set method from md5 in trust编辑文件 pg_hba.conf : set method from md5 in trust

TYPE DATABASE USER ADDRESS METHOD类型数据库用户地址方法

IPv4 local connections: host all all 127.0.0.1/32 trust IPv4 本地连接:托管所有 127.0.0.1/32 信任

IPv6 local connections: host all all ::1/128 trust IPv6 本地连接:host all all ::1/128 trust

............................................................................... ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………………………………

I had this issue when working on a Rails application with PostgreSQL database.我在使用 PostgreSQL 数据库处理 Rails 应用程序时遇到了这个问题。

The database user already had Super admin rights and permissions to the database that I created, but I was still encountering this error:数据库用户已经拥有我创建的数据库的超级管理员权限,但我仍然遇到此错误:

F, [2020-10-23T08:04:06.031161 #8902] FATAL -- : [4229b10c-e16f-4f26-90cc-facd47b2088c] ActionView::Template::Error (FATAL:  password authentication failed for user "prod_user"
FATAL:  password authentication failed for user "prod_user"

Here's how I fixed it :这是我修复它的方法

The issue was that the Database Password for the prod_user specified for my Database environment variable was not correct in my .env file.问题是为我的数据库环境变量指定的prod_user数据库密码在我的.env文件中不正确。

I had to modify it to into the correct one.我不得不将其修改为正确的。

That's all.就这样。

I hope this helps我希望这有帮助

In my case, I found that a later host permissions rule line in the pg_hba.conf file had over-ridden the earlier local line.就我而言,我发现pg_hba.conf文件中较晚的host权限规则行覆盖了较早的local行。 I was correctly configuring the local line to use md5 authentication but the host line was set to ident which I changed to md5我正确地将local线路配置为使用 md5 身份验证,但host线路设置为ident ,我将其更改为md5

Note that using trust is an insecure method, so you shouldn't use it in any production-style deployment.请注意,使用trust是一种不安全的方法,因此您不应在任何生产风格的部署中使用它。

就我而言,我遇到此错误是因为我连接到了错误的端口(5432 而不是 5433)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Postgres&Rails –严重:用户密码验证失败 - Postgres & Rails – FATAL: password authentication failed for user PG :: ConnectionBad:严重:用户的密码身份验证失败 - PG::ConnectionBad: FATAL: password authentication failed for user RSpec:`initialize&#39;:致命:用户密码验证失败 - RSpec: `initialize': FATAL: password authentication failed for user PostgreSQL:致命:用户“ rooms”的密码身份验证失败 - Postgresql: FATAL: password authentication failed for user “rooms” 致命:用户“rails”的对等身份验证失败 - FATAL: Peer authentication failed for user “rails” 产品中的Rails 5:PG :: ConnectionBad:严重:使用Docker的用户“ postgres”的密码身份验证失败 - Rails 5 in prod: PG::ConnectionBad: FATAL: password authentication failed for user “postgres” with Docker Rails/PostgreSQL - PG::ConnectionBad: FATAL: 用户密码验证失败(对于 CI/CD) - Rails/PostgreSQL - PG::ConnectionBad: FATAL: password authentication failed for user (for CI/CD) Rails Capistrano 部署 PG::ConnectionBad:致命:密码验证失败 - Rails Capistrano deploy PG::ConnectionBad: FATAL: password authentication failed 致命:用户“postgres”版本 11 的密码验证失败 - FATAL: password authentication failed for user “postgres” version 11 PG::ConnectionBad: FATAL: 生产服务器上用户“postgres”的密码认证失败 - PG::ConnectionBad: FATAL: password authentication failed for user “postgres” on the production server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM