Allow URI connection string

Issue #189 resolved
Chris Bandy created an issue

libpq has supported URI connection string since PostgreSQL 9.2, Sep 2012.

It would be great to be able to do the following:

conn = PG.connect('postgresql://user:pass@postgresql.lxc:5432/development?sslmode=require')

Discussion on mailing list:!topic/ruby-pg/QyueL4oCq1M

Comments (6)

  1. Paul Jolly

    Any chance we can get this merged in?

    Unless there's another way that I can specify that sslmode=disable?

  2. Eric Radman

    I was able to work around this problem by manually converting the connection string to parameters:

    require "uri"
    conn = URI.parse( ENV['PGHOST'] )
      :host => URI.decode(,
      :port => conn.port,
      :user => conn.user ? conn.user : ENV['USER'],
      :password => conn.password,
      :dbname => conn.path[1..-1]

    Unfortunately adding this kind of parsing into individual applications is almost certainly incomplete (this doesn't handle query string arguments, for example) so official support would be very valuable.

  3. Log in to comment