class PG::Connection

def new(*args)

Raises a PG::Error if the connection fails.

connection will have its +client_encoding+ set accordingly.
If the Ruby default internal encoding is set (i.e., Encoding.default_internal != nil), the

PG::Connection.new( "postgresql://user:pass@pgsql.example.com:5432/testdb?sslmode=require" )
# As an URI

PG::Connection.new( nil, 5432, nil, nil, 'test', nil, nil )
# As an Array

PG::Connection.new( "dbname=test port=5432" )
# As a String

PG::Connection.new( dbname: 'test', port: 5432 )
# As a Hash

PG::Connection.new
# Connect using all defaults

Examples:

login password
[+password+]
login user name
[+user+]
connecting database name
[+dbname+]
(ignored in all versions of PostgreSQL)
[+tty+]
backend options
[+options+]
server port number
[+port+]
server hostname
[+host+]
The positional parameter form has the same functionality except that the missing parameters will always take on default values. The parameters are:

See the documentation of {connection strings}[https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING].
There are two accepted formats for +connection_string+: plain keyword = value strings and URIs.

See the {list of valid parameters}[https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS] in the PostgreSQL documentation.
+connection_hash+ must be a ruby Hash with connection parameters.

Create a connection to the specified server.

PG::Connection.new(host, port, options, tty, dbname, user, password) -> conn
PG::Connection.new(connection_string) -> conn
PG::Connection.new(connection_hash) -> conn
PG::Connection.new -> conn
call-seq:
def new(*args)
	conn = connect_to_hosts(*args)
	if block_given?
		begin
			return yield conn
		ensure
			conn.finish
		end
	end
	conn
end