PostgreSQL service on Rocky Linux: configuring StopWhenUnneeded to control idle connections
0 reputation · 21 Jan 2026, 23:56 UTC
PostgreSQL service on Rocky Linux: configuring StopWhenUnneeded to control idle connections
The goal is to ensure that idle PostgreSQL connections are released when the systemd service is stopped or restarted, thereby reducing the risk of connection pool exhaustion under variable workloads.
Currently the default max_connections is 100, idle_in_transaction_session_timeout is disabled, and the PostgreSQL unit file does not set StopWhenUnneeded, leaving the service loaded and idle connections persisting across stop/start cycles. It is unclear whether enabling StopWhenUnneeded will terminate client connections gracefully or abruptly, and whether additional timeout settings are required to avoid leaving long‑running transactions open.
Does enabling StopWhenUnneeded cause PostgreSQL to close all active connections immediately upon service stop?
Will the combination of StopWhenUnneeded=true and idle_in_transaction_session_timeout>0 provide a safe idle‑connection cleanup mechanism?
Are there any side‑effects on service reliability or failover behavior when StopWhenUnneeded is set?