Postgres error 08006: connection failure
connection failure / server closed the connection unexpectedly
The connection to the server broke while it was in use: the server process ended, the network dropped, or an idle connection was cut by something in between.
Common causes
- The server restarted, or the backend process for this session was terminated (by an administrator, an idle timeout or the out-of-memory killer).
- A proxy, load balancer or NAT dropped an idle TCP connection without telling either side.
- A serverless database scaled to zero and closed sessions that were still open in a pool.
How to fix it
- Retry the statement once on a new connection; most drivers and pools can do this for you.
- Make the pool check connections before use (for example a validation query or a short idle lifetime shorter than any proxy timeout).
- Enable TCP keepalives on the client so idle connections are not silently dropped.
Through a REST API
PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 503 for this error and returns the SQLSTATE in the code field of the JSON error body. Through a REST layer you see a 503 instead; the API reconnects for you on the next request.
Questions
What does Postgres error 08006 mean?
08006 is connection_failure in class 08 (Connection Exception). The connection to the server broke while it was in use: the server process ended, the network dropped, or an idle connection was cut by something in between.
How do I fix 08006?
Retry the statement once on a new connection; most drivers and pools can do this for you. Make the pool check connections before use (for example a validation query or a short idle lifetime shorter than any proxy timeout). Enable TCP keepalives on the client so idle connections are not silently dropped.
What HTTP status does a REST API return for 08006?
PostgREST, the REST layer behind supabase-js, answers 503.
Other class 08 errors
- 08001 could not connect to server / connection refused