Connection URIs

91 views
Skip to first unread message

Chris Bandy

unread,
Apr 22, 2014, 1:23:49 PM4/22/14
to rub...@googlegroups.com
I was surprised to find that I can't connect using a URI as described in the PostgreSQL docs: http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-CONNSTRING

% bundle exec irb -r pg
irb(main):001:0> PG::VERSION
=> "0.17.1"
irb(main):002:0> PG.connect('postgresql://admin:pa...@10.0.3.210/postgres')
PG::ConnectionBad: could not translate host name "postgresql://admin:pa...@10.0.3.210/postgres" to address: Name or service not known
        from /home/vagrant/dev/core-services-database/.bundle/ruby/2.1.0/gems/pg-0.17.1/lib/pg.rb:40:in `initialize'
        from /home/vagrant/dev/core-services-database/.bundle/ruby/2.1.0/gems/pg-0.17.1/lib/pg.rb:40:in `new'
        from /home/vagrant/dev/core-services-database/.bundle/ruby/2.1.0/gems/pg-0.17.1/lib/pg.rb:40:in `connect'
        from (irb):2
        from /usr/bin/irb:11:in `<main>'
irb(main):003:0> PG.connect('user=admin password=pass host=10.0.3.210 dbname=postgres')
=> #<PG::Connection:0x00000001174200 @socket_io=nil, @notice_receiver=nil, @notice_processor=nil>

Is there a technical reason for this?

-- Chris

Michael Granger

unread,
Apr 24, 2014, 12:02:20 PM4/24/14
to rub...@googlegroups.com
On 22 Apr 2014, at 10:23, Chris Bandy wrote:

> I was surprised to find that I can't connect using a URI as described
> in
> the PostgreSQL
> docs:
> http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-CONNSTRING
>
> [...]
>
> Is there a technical reason for this?

There is a reason, of course, but I'm not sure it's technical. URLs as
connection strings is a fairly recent addition to libpq (9.2 I believe),
so it just hasn't been added to pg yet.

I added support for it as a part of a patch I'm working on to try to
make the gem use the newer PQconnectdbParams instead of PQconnectdb, but
since they seem to have un-deprecated PQconnectdb, I stopped work on it.
I'll extract that bit and make it part of the next release.

--
Michael Granger <g...@FaerieMUD.org>
Rubymage, Architect, Believer
The FaerieMUD Consortium <http://faeriemud.org/>

Chris Bandy

unread,
Apr 30, 2014, 3:19:36 PM4/30/14
to rub...@googlegroups.com
On Thursday, April 24, 2014 11:02:20 AM UTC-5, Michael Granger wrote:
On 22 Apr 2014, at 10:23, Chris Bandy wrote:

> I was surprised to find that I can't connect using a URI as described
> in
> the PostgreSQL
> docs:
> http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-CONNSTRING
>
> [...]
>
> Is there a technical reason for this?

There is a reason, of course, but I'm not sure it's technical. URLs as
connection strings is a fairly recent addition to libpq (9.2 I believe),
so it just hasn't been added to pg yet.

I added support for it as a part of a patch I'm working on to try to
make the gem use the newer PQconnectdbParams instead of PQconnectdb, but
since they seem to have un-deprecated PQconnectdb, I stopped work on it.
I'll extract that bit and make it part of the next release.
 
Excellent! I'm excited to use this feature. Please let me know if/how I can help.

-- Chris
Reply all
Reply to author
Forward
0 new messages