Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uZsSt-009S8U-ES for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jul 2025 14:41:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uZsSr-00DjC5-Dy for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jul 2025 14:41:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uZsSr-00DjBo-5f for pgsql-bugs@lists.postgresql.org; Thu, 10 Jul 2025 14:41:33 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uZsSq-006aac-0H for pgsql-bugs@lists.postgresql.org; Thu, 10 Jul 2025 14:41:32 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 56AEfUrt1523825; Thu, 10 Jul 2025 10:41:31 -0400 From: Tom Lane To: a.mitrokhin@postgrespro.ru cc: pgsql-bugs@lists.postgresql.org Subject: Re: Starting a PostgreSQL server on a dynamic port (parameter port=0) In-reply-to: <824bbf6be5fa0edf6a7d4c8371ce67ce@postgrespro.ru> References: <824bbf6be5fa0edf6a7d4c8371ce67ce@postgrespro.ru> Comments: In-reply-to a.mitrokhin@postgrespro.ru message dated "Thu, 10 Jul 2025 14:15:19 +0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1523823.1752158490.1@sss.pgh.pa.us> Date: Thu, 10 Jul 2025 10:41:30 -0400 Message-ID: <1523824.1752158490@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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