tcp_keepalives_idle
Seconds of connection inactivity before the server probes the client with TCP keepalives.
- 默认
0 (OS default)- Range
- 0, or 1 second upward; the accepted maximum is platform dependent
- Restart needed
- 否
- Default checked on
- PostgreSQL 18
作用
0 uses the OS default, commonly 2 hours. The probe rhythm is tuned by tcp_keepalives_interval and, where the OS allows it, tcp_keepalives_count. It covers the server's own socket: with PgBouncer in front, it applies to the pooler-to-server leg, not client to pooler.
默认值
0 (OS default). 0, the OS default (PostgreSQL 18).
Check the current value
SHOW tcp_keepalives_idle; SELECT setting, unit, boot_val, context, source, pending_restart FROM pg_settings WHERE name = 'tcp_keepalives_idle';
Change it
SET tcp_keepalives_idle = 60; -- this session ALTER ROLE reporting SET tcp_keepalives_idle = 60; -- new sessions of one role ALTER SYSTEM SET tcp_keepalives_idle = 60; SELECT pg_reload_conf();
No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).
When to change it
Behind NAT gateways or stateful firewalls that drop idle sessions after a few minutes, a 60s idle time keeps the mapping alive. Also useful to notice dead clients faster than the OS default.
What can go wrong
On systems without the needed socket options it must stay 0, and a nonzero value is rejected when the SET runs. On Windows, 0 does not mean the OS default but a hard 2 hours, because Windows cannot read the system value; Unix-socket sessions ignore it and report 0.
Questions about tcp_keepalives_idle
What is the default value of tcp_keepalives_idle in PostgreSQL?
0 (OS default). 0, the OS default (PostgreSQL 18).
Does changing tcp_keepalives_idle require a restart?
No. No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).
When should I change tcp_keepalives_idle?
Behind NAT gateways or stateful firewalls that drop idle sessions after a few minutes, a 60s idle time keeps the mapping alive. Also useful to notice dead clients faster than the OS default.
Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.
Check tcp_keepalives_idle on your own server
SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.
本页文字和数据: CC BY 4.0,请注明出处 SQLly (sqlly.app)。 代码和 SQL 片段: MIT. 许可详情