# psycopg2.OperationalError: ERROR: could not send data to server: Broken pipe

- **ID:** `database/postgresql-checkpoint-wait-timeout`
- **Domain:** database
- **Category:** connection_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

The PostgreSQL server closed the connection unexpectedly, often due to a timeout (e.g., statement_timeout, idle_in_transaction_session_timeout) or a server crash, causing a broken pipe on the client side.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PostgreSQL 13 | active | — | — |
| PostgreSQL 14 | active | — | — |
| PostgreSQL 15 | active | — | — |

## Workarounds

1. **Check PostgreSQL logs for the reason the connection was terminated (e.g., statement_timeout, idle_in_transaction_session_timeout). Adjust the relevant timeout parameters in postgresql.conf:
statement_timeout = 0  # disable or increase
idle_in_transaction_session_timeout = 0** (80% success)
   ```
   Check PostgreSQL logs for the reason the connection was terminated (e.g., statement_timeout, idle_in_transaction_session_timeout). Adjust the relevant timeout parameters in postgresql.conf:
statement_timeout = 0  # disable or increase
idle_in_transaction_session_timeout = 0
   ```
2. **Enable TCP keepalives on the client side to detect broken connections earlier and automatically reconnect:
import psycopg2
conn = psycopg2.connect("host=... keepalives=1 keepalives_idle=30 keepalives_interval=10 keepalives_count=5")** (75% success)
   ```
   Enable TCP keepalives on the client side to detect broken connections earlier and automatically reconnect:
import psycopg2
conn = psycopg2.connect("host=... keepalives=1 keepalives_idle=30 keepalives_interval=10 keepalives_count=5")
   ```

## Dead Ends

- **Increasing connection pool size in the application** — The error is not about pool exhaustion but about an existing connection being terminated; more connections don't fix broken pipes. (90% fail)
- **Restarting the application without checking server logs** — The underlying cause (e.g., server-side timeout) is not addressed; the error will recur. (85% fail)
