PostgreSQL Service configuration problem

I installed PostgreSQL server on a fresh install of openSuse 13.2 (KDE).
I was able to start the PostgreSQL service. I enabled the service using

systemctl enable postgresql.service

The postgresql service starts successfully after booting the system.
However if I shutdown the system, the PostgreSQL process is killed before the postgres init script is called. Therefore the postgres database is not closed properly and an auto recovery of the database is started when the service is started the next time. This is probably not a reliable solution.
Can someone confirm that this is general problem?

Not specific to PostgreSQL, I can verify that what you’ve observed is generally true of openSUSE ever since systemd was implemented when shutting down… I’ve also seen all sorts of services and processes killed unceremoniously and suddenly instead of gracefully shutting down. The advantage of course is that people are impressed how quickly you can subsequently power off and leave instead of watching and waiting… waiting for a machine to shut down.

I haven’t investigated recently but when I looked into this more than a year ago, the most common recommendation (I considered imperfect) was to increase the time counter(delay) for shutting down. The idea is that you either guess or determine how long it takes for your affected service (PostgreSQL in your case) to shut down, and then set the appropriate value for system shutdown.

To me, that still left much to chance and also might require setting the delay unnecessarily (or necessarily) high to ensure the service(s) shut down. Probably a more elegant solution would be to do something like script inspecting service status, and system shutdown only when all others have shut down. But, to do this correctly might require some thought and experimentation. Maybe a simpler solution is to create a custom shutdown script which first stops the PostgreSQL service before invoking system shutdown. You could even do this by creating a custom Unit file which requires services to stop before executing shutdown.

TSU

Thank you for the information. How do I increase the delay for shutting down?

Hard to remember what I was reading a year ago…

But looking at this today,
I’d recommend you read the MAN pages for

In the following, describes the default timeout settings system-wide and although may not be immediately relevant the watchdog timer defaults (when you start messing with settings, you may want to know the settings that limit when your modification causes unexpected results)

man systemd-system-conf

Note also in the above that describes system-wide timeouts, that service specific settings can be made in the service Unit files and references the following MAN page

man systemd.service

If you resolve your issue, be sure to post your results here again…
As I described, the default system behavior is probably OK for most non-Server (or even Server) configurations, but when running a large database, it’s probably not a good idea to shutdown before all your atomic transactions have been verified executed.

HTH,
TSU

Thanks. I played a bit with different timeout values, without any success, so far. I will report, if I can resolve this.

You should make a bug report. If things are not shutting down properly it is a bug.

You are probaly right; I created a bug report. I will update this thread if there are any results.

Occurred to me we may be over-thinking this problem.

Try this…
Create an executable script with the following simple contents

systemctl stop postgresql.service && shutdown -h now

When you shutdown, just use this script intead of the usual. Of course, if there are any additional apps or services you want stopped instead of killed before shutdown, just add to the script.

HTH,
TSU