web-dev-qa-db-ja.com

Rails PostgreSQLを使用して 'fe_sendauth:パスワードが提供されていません'のエラーを解決する方法は?

Postgresqlデータベースを使用してRailsアプリを作成しようとしましたが、_Rails server_を起動すると、次のエラーが発生しました。

fe_sendauth:パスワードが指定されていません

これが私の行動のステップバイステップです:

_$ Sudo apt-get install postgresql postgresql-contrib
$ gem install pg
$ Rails new timetracker --database=postgresql --skip-unit-test
_

私の_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
_

そして、これが私の_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
_

したがって、_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:パスワードが指定されていません

/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:in_ new'from/home/denis/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in _connect' from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in_ initialize'from /home/denis/.rvm/gems/Ruby -2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in _new' from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in_ postgresql_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:in _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:448:in_ checkout_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:in _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_ block in checkout'from /home/denis/.rvm/rubies/Ruby-2.1.5/lib/Ruby/ 2.1.0/monitor.rb:211:in _mon_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:in_ checkout'from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connectio n_adapters/abstract/connection_pool.rb:263:in _block in connection' from /home/denis/.rvm/rubies/Ruby-2.1.5/lib/Ruby/2.1.0/monitor.rb:211:in_ mon_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:in _connection' from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in_ retrieve_connection '... 4レベル.../home/denis/.rvm/gems/Ruby-2.1.5/gems/railties-4.2.3/lib/Rails/commands/console.rb:9:in _start' from /home/denis/.rvm/gems/Ruby-2.1.5/gems/railties-4.2.3/lib/Rails/commands/commands_tasks.rb:68:in_ console'from /home/denis/.rvm/gems/Ruby-2.1.5/gems/railties-4.2.3/lib/Rails/commands/commands_tasks .rb:39:in _run_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:in _require' from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in_ block in require'from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in _load_dependency' from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in_ require '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:in load'from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activesupport-4.2.3/ lib/active_support /dependencies.rb:268:in _block in load' from /home/denis/.rvm/gems/Ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in_ load_dependency'from /home/denis/.rvm/gem s/Ruby-2.1.5/gems/activesupport-4.2.3/lib/active_support /dependencies.rb:268:in _load' from /home/denis/.rvm/rubies/Ruby-2.1.5/lib/Ruby/site_Ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in_ require'from /home/denis/.rvm/rubies/Ruby-2.1.5/ lib/Ruby/site_Ruby/2.1.0/ruby​​gems/core_ext/kernel_require.rb:54:in _require' from -e:1:in_ '2.1.5:002>

私は初めてpostgresqlを使用していますが、何か間違ったことをしているだけだと思います。

手伝ってくれませんか。

8
Denis Yakovenko

この問題に対する私の解決策は、Host: localhostグループからdefault:を削除することでした。

9
jljohnstone

PostgreSQLはpg_hba.confエントリを指定された順序で照合するため、指定されたtrustエントリの代わりに、事前に指定されたHost all all 127.0.0.1/32 md5エントリを認証に使用します。

カスタムのtrustエントリを事前に指定されたエントリの上に移動し(オプションで古いエントリをコメントアウトし)、Sudo service postgresql reload(Ubuntuの場合)を実行するか再起動して構成を再読み込みします。

6