1. ホーム
  2. postgresql

[解決済み] PostgreSQLを使用するRailsでエラー 'fe_sendauth: no password supplied' を解決するにはどうすればよいですか?

2022-02-01 07:32:44

質問

Railsアプリをpostgresqlのデータベースで作成しようとしましたが 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 初期化' 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'を作成しました。 /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 ブロックのチェックアウト' から /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/connection_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レベル... from /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 コンソール' 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 ' から /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 ブロックが必要です。 /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' は /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/gems/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/rubygems/core_ext/kernel_require.rb:54:in require' from -e:1:in '2.1.5 :002 >

初めてpostgresqlを使うのですが、何か間違っているのでしょうか?

どうかご協力をお願いします。

どのように解決するのですか?

この問題に対する私の解決策は host: localhost から default: というグループを作成します。