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

From: Yurii Rashkovskii <yrashk(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Allow Postgres to pick an unused port to listen
Date: 2023-04-07 21:33:42
Message-ID: CA+RLCQyTov4RhU8J9iRebdMangR7w99i1em23DeZx7NgpjBF+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Andrew,

On Fri, Apr 7, 2023, 7:07 p.m. Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:

>
> On 2023-03-29 We 07:55, Tom Lane wrote:
>
> Yurii Rashkovskii <yrashk(at)gmail(dot)com> <yrashk(at)gmail(dot)com> writes:
>
> I would like to suggest a patch against master (although it may be worth
> backporting it) that makes it possible to listen on any unused port.
>
> I think this is a bad idea, mainly because this:
>
>
> Instead, with this patch, one can specify `port` as `0` (the "wildcard"
> port) and retrieve the assigned port from postmaster.pid
>
> is a horrid way to find out what was picked, and yet there could
> be no other.
>
> Our existing design for this sort of thing is to let the testing
> framework choose the port, and I don't really see what's wrong
> with that approach. Yes, I know it's theoretically subject to
> race conditions, but that hasn't seemed to be a problem in
> practice. It's especially not a problem given that modern
> testing practice tends to not open any TCP port at all, just
> a Unix socket in a test-private directory, so that port
> conflicts are a non-issue.
>
>
> For TAP tests we have pretty much resolved the port collisions issue for
> TCP ports too. See commit 9b4eafcaf4
>
> Perhaps the OP could adapt that logic to his use case.
>

Thank you for referencing this commit. The point why I am suggesting my
patch is that I believe that my solution is a much better way to avoid
collisions in the first place. Implementing an algorithm similar to the one
in the referenced commit is error-pfone and can be difficult in
environments like shell script.

I'm trying to understand what's wrong with reading port from the pid file
(if Postgres writes information there, it's surely so that somebody can
read it, otherwise, why write it in the first placd)? The proposed solution
uses operating system's functionality to achieve collision-free mechanics
with none of the complexity introduced in the commit.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2023-04-07 21:43:24 Re: Show various offset arrays for heap WAL records
Previous Message Alvaro Herrera 2023-04-07 21:33:32 Re: Minimal logical decoding on standbys