Report this

What is the reason for this report?

Configuring POSTGRESQL To Auto-start After Boot using systemd

Posted on April 7, 2022

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?



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!

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.

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/

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

This comment has been deleted

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.