% 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>
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.