PostgreSQL exits after being started
Theres a couple of things going on here. If you call a systemd service with an @
in it, its a signal to start an instance rather than main service. Putting @9.5-main
is telling it the instance parameters to use.
The postgres service file you are seeing is nothing more than a placeholder. There is a directory on the system (its normally somewhere in /run
) called postgresql.wants.d
which the systemd will look for when postgresql.service
is started.
Anything in that directory will be started along with it as postgresql.service
is told it wants it.
That directory is filled through a shell script generator file as everything in /run
is a tmpfs. Thats the shell script you quoted above.
If I had to hazard a guess whats going on there via the logic of the shell script, you probably have got the file /etc/postgresql/9.5/main/start.conf
set to manual
.
This means the generator skips over it and the postgresql.wants.d
never gets added with that instance name.
According to the script logic simply removing it has the right affect of making it auto.
You can also set it to auto
and do a daemon-reload
to regenerate the necessary config.
As of 26 May 2017, the issue still exists on Debian 8 (as far as I can see): PostgreSQL fails to start on boot.
The solution for the time being is to issue:
systemctl daemon-reload
systemctl restart postgresql
manually on boot and everything should be all right. Thanks to Florian Brucker for pointing this out above.
The bug is apparently in systemd and, hopefully, should be rectified soon.