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/rubygems/core_ext/kernel_require.rb:54:in _require' from -e:1:in
_ '2.1.5:002>
私は初めてpostgresqlを使用していますが、何か間違ったことをしているだけだと思います。
手伝ってくれませんか。
この問題に対する私の解決策は、Host: localhost
グループからdefault:
を削除することでした。
PostgreSQLはpg_hba.conf
エントリを指定された順序で照合するため、指定されたtrust
エントリの代わりに、事前に指定されたHost all all 127.0.0.1/32 md5
エントリを認証に使用します。
カスタムのtrust
エントリを事前に指定されたエントリの上に移動し(オプションで古いエントリをコメントアウトし)、Sudo service postgresql reload
(Ubuntuの場合)を実行するか再起動して構成を再読み込みします。