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

From a.mitrokhin@postgrespro.ru
Subject Starting a PostgreSQL server on a dynamic port (parameter port=0)
Date
Msg-id 824bbf6be5fa0edf6a7d4c8371ce67ce@postgrespro.ru
Whole thread Raw
Responses Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)
Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)
List pgsql-bugs
Hello.


Postgres does not allow starting the server with port=0, which prevents
it from obtaining an arbitrary free port from the kernel.


~$ LANG=C pg_ctl -D data -o "-c port=0" start
2025-07-10 05:27:02.785 GMT [702503] FATAL:  0 is outside the valid
range for parameter "port" (1 .. 65535)


This makes it unreliable to start the server in my tests without the
risk of port conflicts with already running programs, unless resorting
to an unreliable and race-condition-prone procedure of reserving ports
in advance.


Could you please fix this?



pgsql-bugs by date:

Previous
From: Amit Kapila
Date:
Subject: Re: BUG #18897: Logical replication conflict after using pg_createsubscriber under heavy load
Next
From: Kirill Reshke
Date:
Subject: Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)