public inbox for pgsql-docs@postgresql.org  
help / color / mirror / Atom feed
Add Restart=on-failure To Example Systemd File
3+ messages / 2 participants
[nested] [flat]

* Add Restart=on-failure To Example Systemd File
@ 2025-11-27 18:55 Andrew Jackson <andrewjackson947@gmail.com>
  2026-03-03 12:22 ` Re: Add Restart=on-failure To Example Systemd File Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Andrew Jackson @ 2025-11-27 18:55 UTC (permalink / raw)
  To: pgsql-docs

Hi,

Currently the systemd file in the documentation does not specify a
restart policy. By default systemd will not attempt to restart a
service that has failed (killed by OOM-killer for example) [0]. The
systemd docs recommends "Setting this to on-failure is the recommended
choice for long-running services, in order to increase reliability by
attempting automatic recovery from errors." I think that Postgres is
probably a good example of a "long-running service". Pgbouncer for
example also uses "Restart=on-failure" [1].

Wondering also if there are any factors that I am not considering
here. Perhaps if this is the case that this is not good blanket
guidance, it would be worth it to provide some guidance around Restart
systemd parameter in the postgres docs.

[0] https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html
[1] https://github.com/pgbouncer/pgbouncer/blob/master/etc/pgbouncer.service

Thanks,
Andrew Jackson


Attachments:

  [text/x-patch] 0001-doc-Add-restart-on-failure-to-example-systemd-file.patch (1.2K, 2-0001-doc-Add-restart-on-failure-to-example-systemd-file.patch)
  download | inline diff:
From 9a0885ecfccbe69d6704d0c0d69347ccc23cdddb Mon Sep 17 00:00:00 2001
From: Andrew Jackson <andrewjackson947@gmail.com>
Date: Thu, 27 Nov 2025 10:45:52 -0600
Subject: [PATCH] doc: Add restart on failure to example systemd file

The documentation previously had a systemd unit file
that would not attempt to recover from process failures
such as OOM's, segfaults, etc. This commit adds
`Restart=on-failure` which tells systemd to attempt to
restart the process after failure. This is the recommended
configuration per the systemd documentation: "Setting this
to on-failure is the recommended choice for long-running
services". Most postgres users will simply copy/paste
what the postgres docs recommend and will probably do
their own research and change the service file to restart
on failure, so might as well set this as the default in
the postgres docs.
---
 doc/src/sgml/runtime.sgml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml
index 0c60bafac63..dbb3b2ef53f 100644
--- a/doc/src/sgml/runtime.sgml
+++ b/doc/src/sgml/runtime.sgml
@@ -491,6 +491,7 @@ ExecReload=/bin/kill -HUP $MAINPID
 KillMode=mixed
 KillSignal=SIGINT
 TimeoutSec=infinity
+Restart=on-failure

 [Install]
 WantedBy=multi-user.target
--
2.49.0



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Add Restart=on-failure To Example Systemd File
  2025-11-27 18:55 Add Restart=on-failure To Example Systemd File Andrew Jackson <andrewjackson947@gmail.com>
@ 2026-03-03 12:22 ` Peter Eisentraut <peter@eisentraut.org>
  2026-03-03 14:56   ` Re: Add Restart=on-failure To Example Systemd File Andrew Jackson <andrewjackson947@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Peter Eisentraut @ 2026-03-03 12:22 UTC (permalink / raw)
  To: Andrew Jackson <andrewjackson947@gmail.com>; pgsql-docs

On 27.11.25 19:55, Andrew Jackson wrote:
> Currently the systemd file in the documentation does not specify a
> restart policy. By default systemd will not attempt to restart a
> service that has failed (killed by OOM-killer for example) [0]. The
> systemd docs recommends "Setting this to on-failure is the recommended
> choice for long-running services, in order to increase reliability by
> attempting automatic recovery from errors." I think that Postgres is
> probably a good example of a "long-running service". Pgbouncer for
> example also uses "Restart=on-failure" [1].

Committed.

I think your argument from the commit message that most users copy their 
systemd unit files from the docs is not quite correct.  Most users use 
what is in packages.  So perhaps you want to check the usual packagings 
and see if they are also using that setting.






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Add Restart=on-failure To Example Systemd File
  2025-11-27 18:55 Add Restart=on-failure To Example Systemd File Andrew Jackson <andrewjackson947@gmail.com>
  2026-03-03 12:22 ` Re: Add Restart=on-failure To Example Systemd File Peter Eisentraut <peter@eisentraut.org>
@ 2026-03-03 14:56   ` Andrew Jackson <andrewjackson947@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Andrew Jackson @ 2026-03-03 14:56 UTC (permalink / raw)
  To: Peter Eisentraut <peter@eisentraut.org>; +Cc: pgsql-docs

Awesome, thank you.

With regard to downstream package managers:

I previously raised an issue with pgdg yum repos which was actioned [0].
The only other package manager that I use is nixpkgs, interestingly they
set their service file's restart policy to "always"[1].

[0]: https://github.com/pgdg-packaging/pgdg-rpms/issues/127
[1]:
https://github.com/NixOS/nixpkgs/blob/e510dca493787fb7dff8ad31c1f215a0e4d7800a/nixos/modules/service...

On Tue, Mar 3, 2026, 6:22 AM Peter Eisentraut <peter@eisentraut.org> wrote:

> On 27.11.25 19:55, Andrew Jackson wrote:
> > Currently the systemd file in the documentation does not specify a
> > restart policy. By default systemd will not attempt to restart a
> > service that has failed (killed by OOM-killer for example) [0]. The
> > systemd docs recommends "Setting this to on-failure is the recommended
> > choice for long-running services, in order to increase reliability by
> > attempting automatic recovery from errors." I think that Postgres is
> > probably a good example of a "long-running service". Pgbouncer for
> > example also uses "Restart=on-failure" [1].
>
> Committed.
>
> I think your argument from the commit message that most users copy their
> systemd unit files from the docs is not quite correct.  Most users use
> what is in packages.  So perhaps you want to check the usual packagings
> and see if they are also using that setting.
>
>


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-03-03 14:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-11-27 18:55 Add Restart=on-failure To Example Systemd File Andrew Jackson <andrewjackson947@gmail.com>
2026-03-03 12:22 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-03 14:56   ` Andrew Jackson <andrewjackson947@gmail.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox