Reputation: 4066
I made a simple-coding-ruby-program for get backups from remote server, and I made a db in postgresql for save information and schedule backups.
The connect with DB was done with ActiveRecord, I configured for access a internal DB (in other server), but when I try to connect to remote db, i get this message:
/usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:968:in `initialize': FATAL: no existe el rol <<mi_user_name>> (PGError)
from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:968:in `connect'
from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:968:in `connect'
from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:217:in `initialize'
from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:37:in `new'
from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'
from /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
from /usr/lib/ruby/1.8/active_record/base.rb:3113:in `quoted_table_name'
from /usr/lib/ruby/1.8/active_record/base.rb:1684:in `construct_finder_sql'
from /usr/lib/ruby/1.8/active_record/base.rb:1548:in `find_every'
from /usr/lib/ruby/1.8/active_record/base.rb:1505:in `find_initial'
from /usr/lib/ruby/1.8/active_record/base.rb:613:in `find'
from main.rb:84:in `main'
from main.rb:126
PG try to connect to remote db with my local user, in the declaration of ActiveRecord I set the parameters:
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:host => "xxx.xxx.x.101",
:port => 5432,
:database => "VB_DB",
:user => "pg_user",
:password => "blahblah"
)
I working with Ruby 1.8.7.
Any idea about this?
thank for reading, and help me.
Grettings.
EDIT
I found the solution:
ActiveRecord::Base.establish_connection( :adapter => "postgresql", :host => "xxx.xxx.x.101", :port => 5432, :database => "VB_DB", :username => "pg_user", :password => "blahblah" )
I used :user and must be :username. Shame on me.
Upvotes: 1
Views: 1451
Reputation: 1368
From the error message, it appears that Postgres doesn't think your user exists in the database.
A good first step to troubleshoot this is to try connecting without involving Ruby at all. Since the 'psql' command-line client uses the same underlying library (assuming you're using the 'pg' gem to connect), in general if you can connect using that, you should be okay to connect from Ruby as well.
Try this:
psql -h xxx.xxx.x.101 -U pg_user -W -l
If this shows you the same error (no existe el rol <<mi_user_name>>
), then you'll need to confirm that your user exists, and create it.
If it shows you a list of databases, we'll have to try something else.
Upvotes: 1