如何使用 PostgreSQL 解决 Rails 中的错误“fe_sendauth:未提供密码”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31593451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resolve the error 'fe_sendauth: no password supplied' in Rails using PostgreSQL?
提问by Denis Yakovenko
I've tried to create my Rails app with postgresql database, but when I started rails server, I got this error:
我试图用 postgresql 数据库创建我的 Rails 应用程序,但是当我开始时rails server,我收到了这个错误:
fe_sendauth: no password supplied
fe_sendauth:未提供密码
Here're my actions step by step:
这是我一步一步的操作:
$ sudo apt-get install postgresql postgresql-contrib
$ gem install pg
$ rails new timetracker --database=postgresql --skip-unit-test
My database.ymlfile looks like this:
我的database.yml文件看起来像这样:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
username: postgres
password:
development:
<<: *default
database: timetracker_development
test:
<<: *default
database: timetracker_test
production:
<<: *default
database: timetracker_production
And here's my pg_hba.conffile:
这是我的pg_hba.conf文件:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# modified by me.
host all all 127.0.0.1/32 trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
So, when I do rails serverI get the error and then here's what I get by doing this:
所以,当我这样做时,rails server我得到了错误,然后这是我通过这样做得到的:
$ rails c
$ ActiveRecord::Base.connection.instance_variable_get(:@config)
2.1.5 :001 > ActiveRecord::Base.connection.instance_variable_get(:@config) PG::ConnectionBad: fe_sendauth: no password supplied
from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in
initialize' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:655:innew' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:655:inconnect' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:242:ininitialize' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:44:innew' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:44:inpostgresql_connection' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:innew_connection' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:incheckout_new_connection' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:inacquire_connection' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:inblock in checkout' from /home/denis/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:inmon_synchronize' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:incheckout' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:inblock in connection' from /home/denis/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:inmon_synchronize' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:inconnection' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:inretrieve_connection' ... 4 levels... from /home/denis/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/console.rb:9:instart' from /home/denis/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:inconsole' from /home/denis/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:inrun_command!' from /home/denis/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands.rb:17:in' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:inrequire' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:inblock in require' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:inload_dependency' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:inrequire' from /home/denis/WEB/Rails/timetracker/bin/rails:8:in<top (required)>' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inload' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inblock in load' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:inload_dependency' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inload' from /home/denis/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /home/denis/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from -e:1:in'2.1.5 :002 >
2.1.5 :001 > ActiveRecord::Base.connection.instance_variable_get(:@config) PG::ConnectionBad: fe_sendauth: 没有提供密码
来自 /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in
initialize' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:655:innew' from /home/denis/.rvm/gems /ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:655:inconnect' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:242:ininitialize' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord -4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:44:innew' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:44:inpostgresql_connection' 来自 /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters /abstract/connection_pool.rb:438:innew_connection' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:incheckout_new_connection' 来自 /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:422 :在acquire_connection' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in从 /home/denis/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:inmon_synchronize' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:incheckout' 从 /home/denis/.rvm/gems/ruby阻止 结帐' -2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:inblock in connection' from /home/denis/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:inmon_synchronize' 来自 /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord -4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:inconnection' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:inretrieve_connection' ... 4 个级别...来自 /home/denis/.rvm/gems/ruby-2.1.5/gems/railties -4.2.3/lib/rails/commands/console.rb:9:instart' from /home/denis/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:inconsole' from /home/denis/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands /commands_tasks.rb:39:inrun_command!' from /home/denis/.rvm/gems/ruby-2.1.5/gems/railties-4.2.3/lib/rails/commands.rb:17:in' 来自 /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:输入require' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in阻止来自 /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:inload_dependency' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:inrequire' 来自 /home/denis/WEB/ Rails/timetracker/bin/rails:8:in<top (required)>' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inload' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inblock in load' from /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:inload_dependency '来自 /home/denis/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inload' from /home/denis/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:inrequire' 来自 /home/denis/.rvm/rubies/ ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from -e:1:in'2.1.5 :002 >
I'm using postgresql for the first time and I guess I'm just doing something wrong.
我第一次使用 postgresql,我想我只是做错了什么。
Could you please help me with that?
你能帮我解决这个问题吗?
回答by jljohnstone
My solution to this problem was to remove host: localhostfrom the default:group.
我对这个问题的解决方案是host: localhost从default:组中删除。
回答by Colonel Thirty Two
PostgreSQL matches pg_hba.confentries in the order they are specified, so it uses the pre-specified host all all 127.0.0.1/32 md5entry for authentication instead of your specified trustentry.
PostgreSQLpg_hba.conf按照指定的顺序匹配条目,因此它使用预先指定的host all all 127.0.0.1/32 md5条目进行身份验证,而不是您指定的trust条目。
Move your custom trustentries above the pre-specified ones (and optionally comment out the old ones) and then reload your configuration by running sudo service postgresql reload(on Ubuntu) or rebooting.
将您的自定义trust条目移到预先指定的条目之上(并可选择注释掉旧条目),然后通过运行sudo service postgresql reload(在 Ubuntu 上)或重新启动来重新加载您的配置。

