pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: a.mitrokhin@postgrespro.ru
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)
Date: Thu, 10 Jul 2025 10:41:30 -0400
Message-ID: <1523824.1752158490@sss.pgh.pa.us> (raw)
In-Reply-To: <824bbf6be5fa0edf6a7d4c8371ce67ce@postgrespro.ru>
References: <824bbf6be5fa0edf6a7d4c8371ce67ce@postgrespro.ru>

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





view thread (9+ messages)  latest in thread

Message-ID: <1523824.1752158490@sss.pgh.pa.us>
Permalink:  ../1523824.1752158490@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1523824.1752158490@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, a.mitrokhin@postgrespro.ru, pgsql-bugs@lists.postgresql.org
  Subject: Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)
  In-Reply-To: <1523824.1752158490@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox