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.