在Ubuntu Server 16上安装networking后,如何强制PostgreSQL启动?

PostgreSQL无法绑定套接字,因为它在networking安装之前启动

我使用Ubuntu服务器16.04.1 LTS和PostgreSQL 9.5。 我通过互联网阅读了很多文档,但没有解决我的问题。

我很确定问题是: PostgreSQL服务尝试在networking接口正确设置之前创build一个套接字。

sudo systemctl status postgresql@9.5-main.service ● [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'. 

我必须使用DHCP(而且我不能改变它)和一个固定租约。 由于我已将listen_address='fixed_ip'postgresql.conf因此集群不会在启动时启动。 这是一切开始…

而且我浪费了两天时间,试图让postgreSQL等待networkingconfiguration没有成功。 它在Ubuntu Server 14.04上的工作就像一个魅力(我没有configuration任何东西),现在它不适用于新的LTS版本。

我至less已经尝试了这些线索:

  • Ubuntu的论坛 ,它删除了另一个错误(开始工作正在运行的networking接口的提高…)
  • NetworkTarget ,它添加了其他错误而我的问题依然存在。

在Ubuntu Server 16上安装networking后,如何强制PostgreSQL启动?

感谢您的帮助

使用新的systemctl服务pipe理器,您可以强制服务等待networking处于活动状态,直到启动。 这是通过编辑服务单元文件(查看/etc/systemd/system/ )并在unit部分中添加以下行来实现的:

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

然后用新configuration重新加载服务:

 systemctl reload name.service 

开始服务之前,重新启动系统以检查是否等待networking。

在服务文件(/etc/init.d/<service>) ,可以指定PostGre必须启动的服务。 这将是这样的:

 #! /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 

在Required-start中,您可以指定networking