Here is a simple Ruby code to connect to PostgreSQL.
gem 'pg' require 'pg' conn = PG::Connection.open(:dbname => 'test') res = conn.exec('SELECT * from table1') res.each do |row| row.each do |column| puts column end end p conn conn.close
If you look deep in PG::Connection library, it contains 7 parameters which you can use just some of them or all of them. Then you can execute your query by the following command.
Note: Your PostgreSQL should have a role set to your database.
CONNECT_ARGUMENT_ORDER = %w[host port options tty dbname user password]