PostgreSQL not listening on local eth1 after reboot

I have a server with 2 networking interfaces - global on eth0, and local on eth1 with IP like 10.181.xx.xx. Running Ubuntu 16.04.

I set up PostgreSQL to listen on this local address, so another server from the network can access it.

The issue is when I reboot DB server, PostgreSQL can not bind to this local address. Having this in postgresql.log:

2016-07-01 15:06:09 GMT LOG:  could not bind IPv4 socket: Cannot assign   requested address
2016-07-01 15:06:09 GMT HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-07-01 15:06:09 GMT WARNING:  could not create listen socket for "10.181.xx.xx"

After doing service postgresql restart all is working.

How can I make Postgres wait until eth1 is up after reboot and bind to it?


Looked into /var/log/syslog and figured out that it was an issue with systemd startup sequence.

Added

After=network-online.target

line into /lib/systemd/system/[email protected] to [Unit] section

So it looks like that:

[Unit]
Description=PostgreSQL Cluster %i
ConditionPathExists=/etc/postgresql/%I/postgresql.conf
PartOf=postgresql.service
ReloadPropagatedFrom=postgresql.service
Before=postgresql.service
After=network-online.target

All started working - PostgreSQL now loads after network is online.