Skip to content

pgwire: add per-session TCP keepalive settings#164369

Merged
trunk-io[bot] merged 1 commit intocockroachdb:masterfrom
rafiss:tcp-keepalive
Feb 26, 2026
Merged

pgwire: add per-session TCP keepalive settings#164369
trunk-io[bot] merged 1 commit intocockroachdb:masterfrom
rafiss:tcp-keepalive

Conversation

@rafiss
Copy link
Collaborator

@rafiss rafiss commented Feb 25, 2026

  • Add PostgreSQL-compatible per-session TCP keepalive session variables
    (tcp_keepalives_idle, tcp_keepalives_interval, tcp_keepalives_count,
    tcp_user_timeout) that override cluster-level defaults when set to
    non-zero values.
  • Add new server.sql_tcp_keep_alive.idle cluster setting to separate idle
    time from probe interval.
  • Move TCP keepalive cluster settings to pkg/server/tcpkeepalive sub-package
    to avoid import cycles between pkg/server and pkg/sql/pgwire.

Resolves: #162328

Release note (sql change): CockroachDB now supports the PostgreSQL
session variables tcp_keepalives_idle, tcp_keepalives_interval,
tcp_keepalives_count, and tcp_user_timeout. These allow per-session
control over TCP keepalive behavior on each connection. A value of 0
(the default) uses the corresponding cluster setting. Non-zero values
override the cluster setting for that session only. Units match
PostgreSQL: seconds for keepalive settings, milliseconds for
tcp_user_timeout.

@rafiss rafiss requested a review from a team as a code owner February 25, 2026 17:46
@trunk-io
Copy link
Contributor

trunk-io bot commented Feb 25, 2026

😎 Merged successfully - details.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rafiss rafiss requested a review from fqazi February 25, 2026 17:47
@rafiss rafiss marked this pull request as draft February 25, 2026 18:06
Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@fqazi reviewed 13 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on rafiss).

@rafiss rafiss marked this pull request as ready for review February 25, 2026 20:18
Add PostgreSQL-compatible per-session TCP keepalive settings
(tcp_keepalives_idle, tcp_keepalives_interval, tcp_keepalives_count,
tcp_user_timeout) that override cluster-level defaults when set to
non-zero values. A value of 0 means "use the cluster setting default."

Also adds a new `server.sql_tcp_keep_alive.idle` cluster setting to
separate idle time from probe interval, which were previously
conflated in `server.sql_tcp_keep_alive.interval`.

The TCP keepalive cluster settings are moved to a new
`pkg/server/tcpkeepalive` sub-package to avoid import cycles between
`pkg/server` and `pkg/sql/pgwire`. The existing setting variable names
in `pkg/server` are preserved as aliases for backward compatibility.

Resolves: cockroachdb#162328

Release note (sql change): CockroachDB now supports the PostgreSQL
session variables `tcp_keepalives_idle`, `tcp_keepalives_interval`,
`tcp_keepalives_count`, and `tcp_user_timeout`. These allow per-session
control over TCP keepalive behavior on each connection. A value of 0
(the default) uses the corresponding cluster setting. Non-zero values
override the cluster setting for that session only. Units match
PostgreSQL: seconds for keepalive settings, milliseconds for
tcp_user_timeout.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@rafiss
Copy link
Collaborator Author

rafiss commented Feb 26, 2026

/trunk merge

tftr!

@trunk-io trunk-io bot merged commit 486df9b into cockroachdb:master Feb 26, 2026
23 of 25 checks passed
@rafiss rafiss deleted the tcp-keepalive branch February 26, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: support per-session TCP keepalive settings like PostgreSQL

3 participants