Question

Configuring POSTGRESQL To Auto-start After Boot using systemd

I’m using PostgreSQL and it often stops working. I want the service of ‘postgreql’ to start automatically according to the article Configuring MYSQL To Auto-start After Boot using systemd which I have tried following but still not working, anyone have an example?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This comment has been deleted

Hello,

In addition to what has already been mentioned regarding automatic restarts after a service crash, you could also enable the service so it starts after a server reboot:

  1. systemctl enable postgresql

Also if your service is crashing often, I would recommend checking your server logs to find out the root cause of the issue. It is likely that your server needs more memory.

Best,

Bobby

Hi @suraphan,

Systemd allows you to configure a service so that it automatically restarts in case it’s crashed.

You can however let systemd auto-restart it in case it fails or is accidentally killed. To do so, you can add the Restart option to the [Service] stanza.

StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
Restart=on-failure
RestartSec=5s

ExecStart=/path/to/daemon

The above will autorestart after your service in this case postgresSQL crashes. Just add the above code to your PostgreSQL Deamon. It should be somewhere in /etc/systemd/system/