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
Answer a question...

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

Bobby Iliev
Site Moderator
Site Moderator badge
April 7, 2022


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.



Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Site Moderator
Site Moderator badge
April 7, 2022

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.




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/