PostgreSQL URI

From: Paul Förster <paul(dot)foerster(at)gmail(dot)com>
To: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: PostgreSQL URI
Date: 2021-02-25 14:45:46
Message-ID: 6E752D6B-487C-463E-B6E2-C32E7FB007EA@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

in https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING it says that the syntax for a PostgreSQL URI is:

postgresql://[user[:password](at)][host][:port][,...][/dbname][?param1=value1&...]

What I don't understand is the [,...] part, i.e. optionally repeating argument.

I know that this is a valid URI:
postgresql://user1:pass1(at)host1:port1,host2:port2/dbname?target_session_attrs=read-write

But is the following valid?
postgresql://user1:pass1(at)host1:port1,user2:pass2(at)host2:port2/dbname?target_session_attrs=read-write

i.e. can (or should) the user[:pass] part be repeated, and possibly can even be different, if I provide more than one host:port information? Or is the user[:pass] part definitely a one-time only argument and must not appear a second time? I don't know how to read this repetition [,...] syntax. A repeat syntax usually means providing more parameters like the one immediately before that, which in this case, is the port.

I think, it should be more correct this way (note the angle bracket):
postgresql://[user[:password](at)][host[:port]][,...][/dbname][?param1=value1&...]

I tried this with psql but failed miserably, though both user1:pass1 and user2:pass2 exist on both databases.

The documentation also claims that any of the parts is optional except the postgresql:// part. This means, specifying a port without a host would be perfectly fine, which IMHO makes no sense.

Can someone enlighten me? Is this just a misleading line to me in the documentation?

Cheers,
Paul

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2021-02-25 15:01:04 Re: converting text to bytea
Previous Message Rumpi Gravenstein 2021-02-25 14:44:43 Postgres Analog of Oracle APPEND hint