Обсуждение: Add Restart=on-failure To Example Systemd File

Поиск
Список
Период
Сортировка

Add Restart=on-failure To Example Systemd File

От
Andrew Jackson
Дата:
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

Вложения

Re: Add Restart=on-failure To Example Systemd File

От
Peter Eisentraut
Дата:
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.




Re: Add Restart=on-failure To Example Systemd File

От
Andrew Jackson
Дата:
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].


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.