diff --git a/lib/sequel/adapters/postgres.rb b/lib/sequel/adapters/postgres.rb index b1218524ec..74880a64a3 100644 --- a/lib/sequel/adapters/postgres.rb +++ b/lib/sequel/adapters/postgres.rb @@ -218,14 +218,16 @@ def initialize(*args) # client encoding for the connection. def connect(server) opts = server_opts(server) - conn = Adapter.connect( - (opts[:host] unless blank_object?(opts[:host])), - opts[:port] || 5432, - nil, '', - opts[:database], - opts[:user], - opts[:password] - ) + connection_params = { + :host => opts[:host], + :port => opts[:port] || 5432, + :tty => '', + :dbname => opts[:database], + :user => opts[:user], + :password => opts[:password], + :connect_timeout => opts[:connect_timeout] || 20 + }.delete_if { |key, value| blank_object?(value) } + conn = Adapter.connect(connection_params) if encoding = opts[:encoding] || opts[:charset] if conn.respond_to?(:set_client_encoding) conn.set_client_encoding(encoding)