Sorry if this question is a little fuzzy, but I am struggling to get my Rails app and postgres database connected on an Amazon Linux setup.
I have used https://github.com/capistrano-plugins/capistrano-postgresql to set up the database after installing the DB.
I'm on Amazon Linux, have setup postgres only with this plugin after running yum install postgresql94 postgresql94-devel postgresql94-server postgresql94-contrib
)
I am currently seeing this error message when my Rails project tries to connect to 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
I am noticing the message PG::ConnectionBad: FATAL: Ident authentication failed for user "testuser_staging"
This tells me that the server actually responds but here ** I need some advice for testing my configuration **
Troubleshooting attempt #1: hba_conf
I have looked at my hba_conf
and attempted to create a line for the testuser_staging
user:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local testproject_staging testuser_staging password
I tried putting both password
and md5
here, but got the same error message that Ident authentication failed
.
I also tried changing to the default peer
which did not work. That gave another error message ('peer authentication failed'), which I understand, since testuser_staging
of course isnt a unix user.
Troubleshooting attempt #2: rails database console
Now, my attempt to connect above was by running cap staging rails:rake:db:migrate
. Could running via capistrano be flawed?. To error that out I logged into the server. It gave the same error message if I navigate to /var/www/testproject/current
and run RAILS_ENV=staging bundle exec rails dbconsole
.
Troubleshooting attempt #3: psql console
On the other hand, on the server I can get a 'password' error by running:
$ psql -U testuser_staging -d testproject
Password for user testuser_staging:
psql: FATAL: password authentication failed for user "testuser_staging"
This seems odd to me. I am getting different error messages from command line postgres and from rails dbconsole.
File contents of database.yml
:
staging:
adapter: postgresql
encoding: unicode
database: testproject_staging
pool: 5
username: testuser_staging
password: 'the_test_pw'
host: localhost
Contents of 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
note the first line, trust
, which I added to provoke locally connection possibilities. That actually works, but not from within Rails.
Question time:
- What can I do to pinpoint my errors here?
- Any trouble-shooting tips to share?
- Any server setup which are prerequisite prior to using this plugin?**
I am aware of other answers explaining how to setup pg_hba.conf
: psql: FATAL: Peer authentication failed for user "dev". Did I make a mistake?