pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Denis Smirnov <darthunix@gmail.com>
To: Diego <mrstephenamell@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: [Proposal] add portaddr like hostaddr
Date: Fri, 28 Aug 2026 11:12:07 +0700
Message-ID: <8067FAF9-B462-4BB1-84A1-DF3D302A7672@gmail.com> (raw)
In-Reply-To: <636a2d5b-adaf-45d7-a255-870682a8cc73@gmail.com>
References: <70436540-9d77-4014-89af-462881ed18d9@gmail.com>
	<1e3b609e-4cf7-4c39-8770-8248c8b81399@gmail.com>
	<63F7ADE6-DF8F-4261-9FEC-89A381E57E6A@gmail.com>
	<ee1051ac-a37e-4f97-901b-fa4dc96400d9@gmail.com>
	<71685CE0-477D-4E4B-ADFE-D3CC3873512C@gmail.com>
	<636a2d5b-adaf-45d7-a255-870682a8cc73@gmail.com>

Hi Diego,

> hostaddr is the first hop, the only thing libpq dials, and host is
> who the user says is at the end of it.

That is not the libpq model.

libpq describes an OS socket endpoint and, when required, a server name.
For TCP, hostaddr is the numeric destination address and port is the
destination port. When hostaddr is absent, host is resolved through DNS.
When both are present, host is retained for TLS and GSSAPI.

host is therefore a name used for address resolution and authentication,
not a general identity at the end of an arbitrary route. Its use as a
.pgpass lookup key does not change that model.

> The patch does not expose two endpoints: it exposes one endpoint and
> one identity.

By two endpoints I meant the two sides of the forwarding mapping created
by pgcli: the local listener and the remote database target.

The socket endpoint used by libpq is already complete:

    127.0.0.1:39907

The remote target:

    db.example.com:5432

belongs to the SSH forwarding configuration owned by pgcli. portaddr
would combine the address from the local endpoint with the port from the
remote endpoint. It does not complete one endpoint.

> What remains is the case where no port can be written in advance,
> because it does not exist yet.

The port exists before pgcli calls libpq. The current pgcli code starts
the SSH tunnel, reads local_bind_ports[0], and then passes that port to
PGExecute. libpq is never asked to connect without a known port.

pgcli creates the tunnel and owns both sides of the mapping. Once the
tunnel is started, pgcli knows the selected local port. It therefore has
all the information needed to construct consistent SSH forwarding and
libpq configuration: SSH maps the local endpoint to the remote database,
while libpq and .pgpass use that local endpoint.

How pgcli stores or generates this mapping is a pgcli implementation
detail. It does not require libpq to introduce a second port.

Best regards,
Denis Smirnov






view thread (11+ messages)  latest in thread

Message-ID: <8067FAF9-B462-4BB1-84A1-DF3D302A7672@gmail.com>
Permalink:  ../8067FAF9-B462-4BB1-84A1-DF3D302A7672@gmail.com/
Also on:    postgresql.org/message-id/8067FAF9-B462-4BB1-84A1-DF3D302A7672@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: darthunix@gmail.com, mrstephenamell@gmail.com
  Subject: Re: [Proposal] add portaddr like hostaddr
  In-Reply-To: <8067FAF9-B462-4BB1-84A1-DF3D302A7672@gmail.com>
  References: <70436540-9d77-4014-89af-462881ed18d9@gmail.com> <1e3b609e-4cf7-4c39-8770-8248c8b81399@gmail.com> <63F7ADE6-DF8F-4261-9FEC-89A381E57E6A@gmail.com> <ee1051ac-a37e-4f97-901b-fa4dc96400d9@gmail.com> <71685CE0-477D-4E4B-ADFE-D3CC3873512C@gmail.com> <636a2d5b-adaf-45d7-a255-870682a8cc73@gmail.com> <8067FAF9-B462-4BB1-84A1-DF3D302A7672@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox