Re: [BUGS] BUG #13793: Please implement IP_FREEBIND option - Mailing list pgsql-bugs

From Christoph Berg
Subject Re: [BUGS] BUG #13793: Please implement IP_FREEBIND option
Date
Msg-id 20180910133309.GE20917@msg.df7cb.de
Whole thread Raw
In response to BUG #13793: Please implement IP_FREEBIND option  (tomek@pipebreaker.pl)
Responses Re: [BUGS] BUG #13793: Please implement IP_FREEBIND option
List pgsql-bugs
Re: tomek@pipebreaker.pl 2015-12-03 <20151203165520.5892.4072@wrigleys.postgresql.org>
> Bug reference:      13793
> Logged by:          Tomasz Torcz
> Email address:      tomek@pipebreaker.pl
> PostgreSQL version: 9.4.5
> Operating system:   Linux
> Description:        
> 
> IP_FREEBIND socket option allows application to bind on IP address, which i
> s not (yet) configured on any interface. 
> I'd like to see Postgresql binding to all specified 'listen_addresses', even
> if some of then are not available at the moment pgsql starts.
> Optionally, postmaster could put in logs information about that action.
> Right know it is:
> 
> LOG:  could not bind IPv6 socket: Cannot assign requested address
> WARNING:  could not create listen socket for "2001:DB8::1"
> 
> It could be:
> LOG:  could not bind IPv6 socket: Cannot assign requested address
> WARNING:  binding anyway to "2001:DB8::1"

Re: To Sebastian Elisa Pfeifer 2018-09-07 <20180907143718.GF29573@msg.df7cb.de>
> Re: Sebastian Elisa Pfeifer 2018-09-07 <ab23ab6a-f54a-4063-be3d-dbc93f5dedd2@ixolit.com>
> > |2018-09-06 14:02:32 UTC LOG: could not bind IPv4 socket: Cannot assign
> > requested address 2018-09-06 14:02:32 UTC HINT: Is another postmaster
> > already running on port 5432? If not, wait a few seconds and retry.
> > 2018-09-06 14:02:32 UTC WARNING: could not create listen socket for
> > "123.123.123.123"|
> > 
> > Possible fix: Adding the parameter After=network-online.target to it's
> > SystemD Unit file.
> > 
> > Our setup includes the setting:
> > listen_addresses = 'localhost,123.123.123.123' (not the real IP)
> 
> Hi,
> 
> thanks for the report.
> 
> I'll have to investigate if that's the correct fix in general. Afaict
> network-online.target does less than what the name says, i.e. some
> interfaces might still be configuring even at that point. Usual
> symptoms are IPv6 devices that are still in address discovery.

According to https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ ,
network-online.target is meant to be used for networking clients that
need to actually access the network. For daemons that merely provide
networking services, the suggested solution is to enable IP_FREEBIND
on the socket:

http://man7.org/linux/man-pages/man7/ip.7.html

       IP_FREEBIND (since Linux 2.4)
              If enabled, this boolean option allows binding to an IP
              address that is nonlocal or does not (yet) exist.  This per‐
              mits listening on a socket, without requiring the underlying
              network interface or the specified dynamic IP address to be up
              at the time that the application is trying to bind to it.
              This option is the per-socket equivalent of the ip_nonlo‐
              cal_bind /proc interface described below.

This had been requested in 2015 in bug #13793. I think it makes sense
to support this. Especially with IPv6, it is very common that
addresses are not yet assigned when services are starting. (I don't
know yet if other OSes support this option as well.)

Do we want that in PostgreSQL?

Christoph


pgsql-bugs by date:

Previous
From: kalyani kaniganti
Date:
Subject: Re: BUG #15376: Postgres sql 9.4.19 pg_upgrade stops with error Thesource cluster was not shut down cleanly.
Next
From: Tom Lane
Date:
Subject: Re: [BUGS] BUG #13793: Please implement IP_FREEBIND option