DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Connections and Authentication / TCP Settings

tcp_keepalives_count

Maximum number of TCP keepalive retransmits. Number of consecutive keepalive retransmits that can be lost before a connection is considered dead. 0 means use the system default.

  • Default: 0
  • Type: integer
  • Range: 0 … 2147483647
  • Applies: Session (any user)

In plain words

How many keepalive probes may go unanswered before the OS gives up on the connection and the server ends that session. 0 means the OS default (9 on Linux).

For DBAs and operators

Sets TCP_KEEPCNT (not supported on Windows, where it must be 0; ignored on Unix-socket sessions). Detection time ≈ idle + interval × count. A count of 3–6 tolerates short packet loss without keeping dead sessions for long. When the count is exhausted the kernel resets the socket and the backend exits with LOG: could not receive data from client: Connection timed out, so its locks, its transaction and its max_connections slot are released.

SELECT pid, client_addr, state, now() - state_change AS idle_for
  FROM pg_stat_activity WHERE state LIKE 'idle%' ORDER BY idle_for DESC;

How to change it

Any user can change it for their session with SET.

See it in context

Client backend Wire protocol

Related parameters

tcp_keepalives_idle tcp_keepalives_interval tcp_user_timeout

All Connections and Authentication parameters