很抱歉,如果这个问题有点模糊,但我很难在Amazon Linux设置上连接我的Rails应用程序和postgres数据库。
我在安装数据库后使用https://github.com/capistrano-plugins/capistrano-postgresql来设置数据库。
我在亚马逊Linux上运行yum install postgresql94 postgresql94-devel postgresql94-server postgresql94-contrib
后只使用此插件设置了postgres
当我的Rails项目尝试连接到postgres
时,我当前看到此错误消息DEBUG [4f02c446] Tasks: TOP => db:migrate
DEBUG [4f02c446] (See full trace by running task with --trace)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@testproject: rake exit status: 1
rake stdout: Nothing written
rake stderr: config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
rake aborted!
PG::ConnectionBad: FATAL: Ident authentication failed for user "testuser_staging"
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/connection_handling.rb:87:in `connection'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:916:in `initialize'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:823:in `new'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:823:in `up'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:801:in `migrate'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/var/www/testproject/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
我注意到消息 PG::ConnectionBad: FATAL: Ident authentication failed for user "testuser_staging"
这告诉我服务器实际响应但是在这里**我需要一些建议来测试我的配置**
我查看了我的hba_conf
并试图为testuser_staging
用户创建一行:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local testproject_staging testuser_staging password
我尝试同时放置password
和md5
,但收到的错误信息是Ident authentication failed
。
我也尝试过更改为默认peer
,但这不起作用。这给出了另一条错误消息(&#39;对等身份验证失败&#39;),我理解,因为testuser_staging
当然不是unix用户。
现在,我尝试连接上面的内容是运行cap staging rails:rake:db:migrate
。可以通过capistrano运行有缺陷吗?出错我登录到服务器。如果我导航到/var/www/testproject/current
并运行RAILS_ENV=staging bundle exec rails dbconsole
。
另一方面,在服务器上我可以获得一个密码&#39;运行错误:
$ psql -U testuser_staging -d testproject
Password for user testuser_staging:
psql: FATAL: password authentication failed for user "testuser_staging"
这对我来说似乎很奇怪。我从命令行postgres和rails dbconsole获取不同的错误消息。
database.yml
的文件内容:
staging:
adapter: postgresql
encoding: unicode
database: testproject_staging
pool: 5
username: testuser_staging
password: 'the_test_pw'
host: localhost
pg_hba.conf
的内容:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
local testproject_staging testuser_staging password
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
注意我添加的第一行trust
以激发本地连接的可能性。这确实有效,但不是来自Rails。
我知道其他答案,解释了如何设置pg_hba.conf
:psql: FATAL: Peer authentication failed for user "dev"。我犯了错误吗?