You may use ActiveRecord::Base.establish_connection
to switch database connection. Code should be like this:
#database.yml
development:
adapter: postgresql
host: 127.0.0.1
username: postgres
password: postgres
database: development_db
development_another_db:
adapter: postgresql
host: 127.0.0.1
username: postgres
password: postgres
database: another_db
ActiveRecord::Base.establish_connection :development_another_db
sql = "Select * from ... your sql query here"
records_array = ActiveRecord::Base.connection.execute(sql)
ActiveRecord::Base.establish_connection :development
sql = "Another select"
records_array = ActiveRecord::Base.connection.execute(sql)
You may find details about establish_connection
in Rails documentation.