Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)

Laurenz Albe <laurenz.albe@cybertec.at>

From: Laurenz Albe <laurenz.albe@cybertec.at>
To: a.mitrokhin@postgrespro.ru, Kirill Reshke <reshkekirill@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2025-07-10T08:53:17Z
Lists: pgsql-bugs
On Thu, 2025-07-10 at 15:29 +0700, a.mitrokhin@postgrespro.ru wrote:
> > > Postgres does not allow starting the server with port=0, which prevents
> > > it from obtaining an arbitrary free port from the kernel.
> 
> This has nothing to do with Postgres regression tests. The issue is
> the practical benefit of using a dynamic port, which we're depriving
> ourselves of.
> 
> If you're not interested in this behavior, you'll never use it. But
> there are cases where it can be very convenient. Why artificially
> restrict functionality that is simple, doesn't conflict with anything,
> and has no negative side effects?

I have never wished for such a feature, and I can see negative side
effects.  If the server listens on a different port than you expect,
it is easier to connect to the wrong server by mistake.

Yours,
Laurenz Albe