pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Euler Taveira <euler@eulerto.com>
To: David G. Johnston <david.g.johnston@gmail.com>
To: a.mitrokhin@postgrespro.ru <a.mitrokhin@postgrespro.ru>
Cc: Kirill Reshke <reshkekirill@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)
Date: Thu, 10 Jul 2025 11:12:22 -0300
Message-ID: <f2dbeec9-7618-4061-801c-6fc08966afb8@app.fastmail.com> (raw)
In-Reply-To: <CAKFQuwbO6frSLj3w+UYV9reoML=3UFkXbvH5+QJsCNMdaQAxxA@mail.gmail.com>
References: <824bbf6be5fa0edf6a7d4c8371ce67ce@postgrespro.ru>
	<CALdSSPgNJWenx+wGt2pL4oFcuZw21=C3B8AB27b_kayuWZB6yw@mail.gmail.com>
	<a03d0696a0b98a1e91947ffdefa9d6fc@postgrespro.ru>
	<CAKFQuwbO6frSLj3w+UYV9reoML=3UFkXbvH5+QJsCNMdaQAxxA@mail.gmail.com>

On Thu, Jul 10, 2025, at 10:21 AM, David G. Johnston wrote:
> On Thursday, July 10, 2025, <a.mitrokhin@postgrespro.ru> wrote:
>> 
>> 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?
>
> Then figure out how to do it on all the OSes we support and propose a 
> patch.  Maybe it’s simple enough to include.  Maybe not.  If it is 
> simple e on an OS one cares about a shell script around pg_ctl is a 
> simple way to leverage it so it’s still a fairly low priority to add 
> into core.
>

I don't think it is just a matter of operating system supports it. Linux and
Windows supports port 0 but FreeBSD does not.

The RFC 63335 [1] that is referred in the IANA document [2] says:

Reserved: Reserved port numbers are not available for regular
assignment; they are "assigned to IANA" for special purposes.
Reserved port numbers include values at the edges of each range,
e.g., 0, 1023, 1024, etc., which may be used to extend these
ranges or the overall port number space in the future.

Some operating systems like Linux and Windows decided to use it to
automatically assign a free port. I don't think it is a good idea for
production. The main reason is security, we had some reports[3][4] in the past.
Some services like apache and nginx that don't allow you to use port 0.

IMO it could be supported for development purposes. However, the test suite
(pg_regress and TAP tests) already has some logic to assign a port from the
private range (49152-65535) and is capable of assigning another port if the
current port is in use. Maybe the OP has a case that the current approach is
not ideal.

[1] https://www.rfc-editor.org/rfc/rfc6335.html
[2] https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
[3] https://medium.com/@ian.barwise/socket-programming-the-bizarre-tcp-ip-port-0-saga-b5c302d04299
[4] https://nvd.nist.gov/vuln/detail/cve-2023-27567#:~:text=Description,rule%20can%20crash%20the%20kerne....


-- 
Euler Taveira
EDB   https://www.enterprisedb.com/





view thread (9+ messages)  latest in thread

Message-ID: <f2dbeec9-7618-4061-801c-6fc08966afb8@app.fastmail.com>
Permalink:  ../f2dbeec9-7618-4061-801c-6fc08966afb8@app.fastmail.com/
Also on:    postgresql.org/message-id/f2dbeec9-7618-4061-801c-6fc08966afb8@app.fastmail.com

 · 

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: euler@eulerto.com, david.g.johnston@gmail.com, a.mitrokhin@postgrespro.ru, reshkekirill@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: Starting a PostgreSQL server on a dynamic port (parameter port=0)
  In-Reply-To: <f2dbeec9-7618-4061-801c-6fc08966afb8@app.fastmail.com>

* 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