Re: Starting a PostgreSQL server on a dynamic port (parameter port=0) - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)
Date
Msg-id 1523824.1752158490@sss.pgh.pa.us
Whole thread Raw
In response to Starting a PostgreSQL server on a dynamic port (parameter port=0)  (a.mitrokhin@postgrespro.ru)
List pgsql-bugs
a.mitrokhin@postgrespro.ru writes:
> Postgres does not allow starting the server with port=0, which prevents
> it from obtaining an arbitrary free port from the kernel.

Others have already pointed out problems with this proposal, but
the one I see is: what do you do next?  How will clients know
what port to connect to?

The only way I could see to do that is to read the port out of
postmaster.pid, which works only for clients running as the same
userid as the postmaster, which is surely an unfit-for-production
approach.

If you're only interested in this for testing purposes, we
already have perfectly good free-port-selection algorithms
embedded in our test harnesses.  For that matter, in a test
environment it's usually best (most secure) to use a Unix
socket in a private directory, in which case there is little
need to worry about port number conflicts in the first place.

            regards, tom lane



pgsql-bugs by date:

Previous
From: "Euler Taveira"
Date:
Subject: Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)
Next
From: Tom Lane
Date:
Subject: Re: PostgreSQL 18 beta1 - Segmentation fault on custom type casting