Subject: Re: [PATCH] Allow Postgres to pick an unused port to listen

From: Alvaro Herrera <[email-masked]>
Date: Mon, 8 May 2023 16:43:01 +0200

On 2023-Apr-19, Yurii Rashkovskii wrote:

> If we consider this path, then (if we assume the format of the file is
> still to be private), we can make the port line accept multiple ports using
> a delimiter like `:` so that the next line still remains the same.

This made me wonder if storing the unadorned port number is really the
best way.  Suppose we did extend things so that we listen on different
ports on different interfaces; how would this scheme work at all?  I
suspect it would be simpler to store both the interface address and the
port, perhaps separated by :.  You would keep it to one pair per line,
so you'd get the IPv6 address/port separately from the IPv4 address, for
example.  And if you happen to have multiple addresses, you know exactly
which ones you're listening on.

To match a problem that has been discussed in the lists previously,
suppose you have listen_addresses='localhost' and the resolver does
funny things with that name (say you mess up /etc/hosts after starting).
Things would be much simpler if you knew exactly what the resolver did
at postmaster start time.

> (I consider this feature so small that it doesn't deserve such a lengthy
> discussion. However, I also get Tom's point about how we document this

You should see the discussion that led to the addition of psql's 'exit'
command sometime:
https://www.postgresql.org/message-id/flat/CALVFHFb-C_5_94hueWg6Dd0zu7TfbpT7hzsh9Zf0DEDOSaAnfA%40mail.gmail.com#949321e44856b7fa295834d6a3997ab4

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"Every machine is a smoke machine if you operate it wrong enough."
https://twitter.com/libseybieda/status/1541673325781196801

---

From: Tom Lane <[email-masked]>
Date: Mon, 08 May 2023 10:49:28 -0400

Alvaro Herrera <[email-masked]> writes:
> ports on different interfaces; how would this scheme work at all?

Yeah, the probability that that will happen someday is one of the
things bothering me about this proposal.  I'd rather change the
file format to support that first (it can be dummy for now, with
all lines showing the same port), and then document it second.

			regards, tom lane

---

From: Yurii Rashkovskii <[email-masked]>
Date: Thu, 11 May 2023 09:01:37 +0200

Alvaro, Tom,

> all lines showing the same port), and then document it second.

How soon do you think the change will occur that will allow for choosing
different ports on different interfaces? I am happy to help address this.

Relying on a variable number of lines may be counter-productive here if we
want postmaster.pid to be easily readable by shell scripts. What if we
improved the port line to be something like this?

```
127.0.0.1=5432 ::1=54321
```

Basically, a space-delimited set of address/port pairs (delimited by `=` to
allow IPv6 addresses to use a colon). If we allow the address side to be
dropped, the current format (`5432`) will also be correct parsing-wise.

-- 
Y.