# tcp_keepalives_idle

> Seconds of connection inactivity before the server probes the client with TCP keepalives.

Source: https://sqlly.app/sql-configuration/postgresql/tcp-keepalives-idle
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).

**Default**

`0 (OS default)`

**Range**

0, or 1 second upward; the accepted maximum is platform dependent

**Restart needed**

No

**Default checked on**

PostgreSQL 18

## What it does

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.

## Default value

`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](https://sqlly.app/sql-configuration/postgresql), or check the [PostgreSQL manual](https://www.postgresql.org/docs/current/runtime-config.html) for every option.

## Related PostgreSQL settings

- [`idle_session_timeout` Terminate sessions that sit idle waiting for a client query longer than this; 0 disables.](https://sqlly.app/sql-configuration/postgresql/idle-session-timeout)
- [`idle_in_transaction_session_timeout` Terminate sessions that sit idle inside an open transaction for longer than this; 0 disables.](https://sqlly.app/sql-configuration/postgresql/idle-in-transaction-session-timeout)
