大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 probl…

问题原文

原帖链接 · jlandercy · CC BY-SA 3.0

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 omitted]
● [email omitted] - PostgreSQL Cluster 9.5-main
   Loaded: loaded (/lib/systemd/system/postgresql@.service; 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 omitted][5274]: The PostgreSQL server failed to start. Please check the log outp
Jul 27 09:42:36 airpy-server [email omitted][5274]: 2016-07-27 09:42:36 UTC [5332-1] LOG:  could not bind IPv4 socke
Jul 27 09:42:36 airpy-server [email omitted][5274]: 2016-07-27 09:42:36 UTC [5332-2] HINT:  Is another postmaster al
Jul 27 09:42:36 airpy-server [email omitted][5274]: 2016-07-27 09:42:36 UTC [5332-3] WARNING:  could not create list
Jul 27 09:42:36 airpy-server [email omitted][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 omitted]: 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 omitted]: Unit entered failed state.
Jul 27 09:42:36 airpy-server systemd[1]: [email omitted]: 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

已采纳解答

原帖链接 · jlandercy · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。