Notes on implementing URI syntax for libpq - Mailing list pgsql-hackers

From Alexander Shulgin
Subject Notes on implementing URI syntax for libpq
Date
Msg-id 1321899990-sup-1235@moon
Whole thread Raw
Responses Re: Notes on implementing URI syntax for libpq
Re: Notes on implementing URI syntax for libpq
List pgsql-hackers
Hello,

It was proposed a while ago for libpq to support URI syntax for specifying the connection information:
 http://archives.postgresql.org/message-id/1302114698.23164.17.camel@jd-desktop
http://archives.postgresql.org/pgsql-hackers/2011-07/msg01144.php

It appears to me that the consensus was that: 1) this feature is indeed going to be useful, and 2) that we would go by
implementinga simple URI parser ourselves instead of adding dependency on any fancy external library. 

Now we're going to actually implement this.

It is known that libpq (and, thus every utility using it to connect a database: psql, pg_dump, etc.) supports a way to
specifysome of the connection parameters (or all of them) via a single conninfo string, e.g: 
 psql -d "dbname=mydb host=example.net port=5433"

This, in my opinion, is very similar to what we would like to achieve with the URI syntax, so the above could also be
specifiedusing a URI parameter like this: 
 psql -d postgresql://example.net:5433/mydb

We can also support specifying extra parameters via the usual "?keyword=value&keyword2=other" syntax.  As it was noted
inthe original discussion, sticking to what JDBC provides makes the most sense: 
 http://jdbc.postgresql.org/documentation/head/connect.html

So we should support 'user', 'password' and 'ssl' parameters (and probably just ignore the rest, at least for start.)

Upon libpq code inspection I come to think that the best place to plug this seems to be conninfo_array_parse function
(wheredbname keyword is currently being checked for '=' symbol and expanded): 

http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/libpq/fe-connect.c;h=ed9dce941e1d57cce51f2c21bf29769dfe2ee542;hb=HEAD#l4262

We could similarly check for "postgresql:" designator and if present, extract the connection options from the dbname
keywordthought to be a connection URI.  The check should obviously go before the current check for '=', if we're going
supportthe extra parameters, as outlined above. 

I am going to sketch a work-in-progress patch in the background of a discussion here.

Your thoughts on this are very welcome!
--
Alex


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Removing postgres -f command line option
Next
From: Robert Haas
Date:
Subject: Re: COUNT(*) and index-only scans