Configuration parameter

tcp_keepalives_count — PostgreSQL configuration parameter

Category Connections and Authentication

Specifies the number of TCP keepalive messages that can be lost before the server’s connection to the client is considered dead.

At a glance

Property Value
Parameter tcp_keepalives_count
Category Connections and Authentication
Default 0
Value type integer
Change scope Per-session (SET)
Available in PostgreSQL 12, 13, 14, 15, 16, 17, 18, 19 (added in 12)

What it does

Specifies the number of TCP keepalive messages that can be lost before the server’s connection to the client is considered dead. A value of 0 (the default) selects the operating system’s default. This parameter is supported only on systems that support TCP_KEEPCNT or an equivalent socket option (which does not include Windows); on other systems, it must be zero. In sessions connected via a Unix-domain socket, this parameter is ignored and always reads as zero.

(Description quoted from the official PostgreSQL documentation.)

How to apply a change

Can be set per session with SET, per role/database with ALTER ROLE/DATABASE ... SET, or globally in postgresql.conf.

Inspect the current value and source with SHOW tcp_keepalives_count; or SELECT name, setting, unit, context, source FROM pg_settings WHERE name = 'tcp_keepalives_count';.

Tuning guidance

Number of unacknowledged keepalive probes before the connection is dropped; lower it for faster dead-peer detection, raise it to tolerate transient network blips.

Reference

PostgreSQL documentation — tcp_keepalives_count.

Keep going

Related & next steps

Was this helpful?

← All configuration parameters