Home > database >  RDS PostgreSQL - what is the maximum value and default value for keepalives_idle?
RDS PostgreSQL - what is the maximum value and default value for keepalives_idle?

Time:10-10

I am using AWS RDS PostgreSQL.

According to this documentation, keepalives_idle can be used to control the number of seconds of inactivity. It says, "A value of zero uses the system default."

Q1. What is the system default?

According to this, some databases require keepalives_idle less than a maximum value.

Q2. What would be the maximum value for keepalives_idle?

I can't find any resources to answer these two questions.

CodePudding user response:

This is a client side setting while connecting to PostgreSQL database. This doesn't have to do anything with AWS RDS. As the document says, this parameter is only valid for connections made via keeping the setting keepalives to 1 (which is the default).

Since the doc says:

It is only supported on systems where TCP_KEEPIDLE or an equivalent socket option is available.

both tcp_keepalive_time and tcp_keepidle should be used for this parameter whichever is available in the OS.

The system default is the value at /proc/sys/net/ipv4/tcp_keepalive_time. Just do:

$ cat /proc/sys/net/ipv4/tcp_keepalive_time

which should be 7200 (seconds). Some systems also use tcp_keepidle which is equivalent to tcp_keepalive_time. For example, IBM AIX which is a UNIX based OS uses tcp_keepidle (whose default value is also 7200 seconds). To see which systems use which value for sending the probe after the connection is idle, you can refer this.

According to the Linux Man page, /proc interfaces are used to set system-wide TCP parameter settings. So, setting tcp_keepalive_time either by:

$ echo 600 > /proc/sys/net/ipv4/tcp_keepalive_time

or modifying the values in /etc/sysctl.conf would modify the setting system wide. While TCP_KEEPIDLE is used while writing any user specific socket communications that can be set using setsockopt function call.

You can optionally also choose to set this parameter manually while making connection to a PostgreSQL database. If using psql, you can do:

$ echo "SET tcp_keepalives_idle = 42;" >> ~/.psqlrc

and then proceed with psql connection. You can see a variety of options here.

  • Related