It was proposed a while ago for libpq to support URI syntax for specifying the connection information:
It appears to me that the consensus was that:
1) this feature is indeed going to be useful,
2) that we would go by implementing a 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 specify some 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 specified using 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 in the original discussion, sticking to what JDBC provides makes the most sense:
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 (where dbname keyword is currently being checked for '=' symbol and expanded):
We could similarly check for "postgresql:" designator and if present, extract the connection options from the dbname keyword thought to be a connection URI. The check should obviously go before the current check for '=', if we're going support the 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!
pgsql-hackers by date
|Next:||From: Robert Haas||Date: 2011-11-21 18:43:09|
|Subject: Re: COUNT(*) and index-only scans|
|Previous:||From: Bruce Momjian||Date: 2011-11-21 18:27:24|
|Subject: Re: Removing postgres -f command line option|