4

PostgreSQL fails to bind socket because it starts before network is setup.

I use Ubuntu Server 16.04.1 LTS and PostgreSQL 9.5. I have read many docs over the internet but nothing solved my problem.

I am pretty sure that the problem is: PostgreSQL service try to create a socket before Network Interface is properly setup.

sudo systemctl status [email protected][email protected] - PostgreSQL Cluster 9.5-main Loaded: loaded (/lib/systemd/system/[email protected]; disabled; vendor preset: enabled) Active: failed (Result: exit-code) since Wed 2016-07-27 09:42:36 UTC; 1min 43s ago Process: 5274 ExecStart=postgresql@%i --skip-systemctl-redirect %i start (code=exited, status=1/FAILURE) Jul 27 09:42:34 airpy-server systemd[1]: Starting PostgreSQL Cluster 9.5-main... Jul 27 09:42:36 airpy-server [email protected][5274]: The PostgreSQL server failed to start. Please check the log outp Jul 27 09:42:36 airpy-server [email protected][5274]: 2016-07-27 09:42:36 UTC [5332-1] LOG: could not bind IPv4 socke Jul 27 09:42:36 airpy-server [email protected][5274]: 2016-07-27 09:42:36 UTC [5332-2] HINT: Is another postmaster al Jul 27 09:42:36 airpy-server [email protected][5274]: 2016-07-27 09:42:36 UTC [5332-3] WARNING: could not create list Jul 27 09:42:36 airpy-server [email protected][5274]: 2016-07-27 09:42:36 UTC [5332-4] FATAL: could not create any TC Jul 27 09:42:36 airpy-server systemd[1]: [email protected]: Control process exited, code=exited status=1 Jul 27 09:42:36 airpy-server systemd[1]: Failed to start PostgreSQL Cluster 9.5-main. Jul 27 09:42:36 airpy-server systemd[1]: [email protected]: Unit entered failed state. Jul 27 09:42:36 airpy-server systemd[1]: [email protected]: Failed with result 'exit-code'. 

I must use DHCP (and I cannot change it) with a fixed lease. Since I have set the listen_address='fixed_ip' into postgresql.conf the cluster does not start at boot. This is how everything started...

And I have wasted two days trying to make postgreSQL wait for Network configuration without success. It was working like a charm on Ubuntu Server 14.04 (I had nothing to configure) and now it just does not work for the new LTS release.

I have, at least, tried those leads:

  • Ubuntu-Forum, it removed another errors (A start job is running for Raise of network interface...)
  • NetworkTarget, it added other errors And my problem remains.

How can I force PostgreSQL to start after network is setup on Ubuntu Server 16?

Thank you for your help

7
  • Did you manage to solve that? I'm running into the same issue (I want to wait for docker network to be available). Commented Sep 19, 2017 at 8:23
  • 1
    @Matthieu, yes I did after few weeks more documentation were available. Then I have modified my unit file, in order to wait for network.service Commented Sep 19, 2017 at 12:18
  • Would you mind posting an answer describing how you achieved it? It would be really helpful. Thanks! Commented Sep 19, 2017 at 12:50
  • I would but I am busy right now. Commented Sep 19, 2017 at 14:15
  • @Matthieu added answer Commented Sep 19, 2017 at 21:41

2 Answers 2

4

Using new systemctl service manager, you can force service to wait for network is active until it starts. This is achieved by editing the service unit file (look in /etc/systemd/system/) and adding following lines in unit section:

[Unit] Wants=network-online.target After=network-online.target 

Then reload service with the new configuration:

systemctl reload name.service 

Reboot the system to check it wait for network before starting service.

0

In the service file (/etc/init.d/<service>) you can specify after which service PostGre must start. It would be like this :

#! /bin/sh ### BEGIN INIT INFO # Provides: sshd # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: # Short-Description: OpenBSD Secure Shell server ### END INIT INFO 

In the Required-start you can specify networking

1
  • 1
    I already have a $network entry in this file. I think this kind of configuration is deprecated because now it is systemctl which handle it using service units. Commented Jul 27, 2016 at 13:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.