Postgres keep alive configuration

Started by Fabrice Chapuis6 months ago3 messages
#1Fabrice Chapuis
fabrice636861@gmail.com

Hi,

I try to configure these 3 parameters to activate keep alive on a sever
Postgres in version 14.

tcp_keepalives_idle = 3
tcp_keepalives_interval = 2
tcp_keepalives_count = 30

After issuing alter system set ... command and a pg_reload_conf(); these
parameters keep value 0.

I also check these OS parameters
grep TCP_KEEPIDLE /usr/include/netinet/tcp.h
#define TCP_KEEPIDLE 4 /* Start keeplives after this period */

grep TCP_KEEPINTVL /usr/include/netinet/tcp.h
#define TCP_KEEPINTVL 5 /* Interval between keepalives */

grep TCP_KEEPCNT /usr/include/netinet/tcp.h
#define TCP_KEEPCNT 6 /* Number of keepalives before death */

and

sysctl net.ipv4.tcp_keepalive_time
net.ipv4.tcp_keepalive_time = 7200

Thanks for helping on this point

Fabrice

#2Daniel Westermann (DWE)
daniel.westermann@dbi-services.com
In reply to: Fabrice Chapuis (#1)
Re: Postgres keep alive configuration

From: Fabrice Chapuis <fabrice636861@gmail.com>
Sent: Wednesday, July 23, 2025 13:20
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Postgres keep alive configuration
 
Hi,

I try to configure these 3 parameters to activate keep alive on a sever Postgres in version 14.

tcp_keepalives_idle = 3
tcp_keepalives_interval = 2
tcp_keepalives_count = 30

After issuing alter system set ... command and a pg_reload_conf(); these parameters keep value 0.

Did you create a connection over the network when checking the values or are you connected over a socket? For socket connections these values will always be 0.

Regards
Daniel

#3Fabrice Chapuis
fabrice636861@gmail.com
In reply to: Daniel Westermann (DWE) (#2)
Re: Postgres keep alive configuration

Ok Thanks Daniel

It show the right value with the connection over the network

Regards

Fabrice

postgres [2867156]=> show tcp_keepalives_idle;
+---------------------+
| tcp_keepalives_idle |
+---------------------+
| 3 |
+---------------------+
(1 row)

On Wed, Jul 23, 2025 at 1:30 PM Daniel Westermann (DWE) <
daniel.westermann@dbi-services.com> wrote:

Show quoted text

From: Fabrice Chapuis <fabrice636861@gmail.com>
Sent: Wednesday, July 23, 2025 13:20
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Postgres keep alive configuration

Hi,

I try to configure these 3 parameters to activate keep alive on a sever

Postgres in version 14.

tcp_keepalives_idle = 3
tcp_keepalives_interval = 2
tcp_keepalives_count = 30

After issuing alter system set ... command and a pg_reload_conf(); these

parameters keep value 0.

Did you create a connection over the network when checking the values or
are you connected over a socket? For socket connections these values will
always be 0.

Regards
Daniel