Skip site navigation (1) Skip section navigation (2)

Notes on implementing URI syntax for libpq

From: Alexander Shulgin <ash(at)commandprompt(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Notes on implementing URI syntax for libpq
Date: 2011-11-21 18:35:16
Message-ID: 1321899990-sup-1235@moon (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers

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 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://

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):;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 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 HaasDate: 2011-11-21 18:43:09
Subject: Re: COUNT(*) and index-only scans
Previous:From: Bruce MomjianDate: 2011-11-21 18:27:24
Subject: Re: Removing postgres -f command line option

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group