Postgres error 08001: sqlclient unable to establish sqlconnection
could not connect to server / connection refused
The client could not open a connection at all, before any authentication happened.
Common causes
- Wrong host or port, or the server is not listening on that address.
- A firewall, security group or IP allow list blocks the client address.
- The server is down, starting up, or waking from scale to zero and the client gave up too early.
- TLS was required by the server but not offered by the client (or the reverse).
How to fix it
- Check host, port and sslmode in the connection string; try psql with the same string to separate app problems from network problems.
- Add the client IP to the allow list, or connect from an allowed network.
- Raise the connect timeout for databases that may be asleep.
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.
Questions
What does Postgres error 08001 mean?
08001 is sqlclient_unable_to_establish_sqlconnection in class 08 (Connection Exception). The client could not open a connection at all, before any authentication happened.
How do I fix 08001?
Check host, port and sslmode in the connection string; try psql with the same string to separate app problems from network problems. Add the client IP to the allow list, or connect from an allowed network. Raise the connect timeout for databases that may be asleep.
What HTTP status does a REST API return for 08001?
PostgREST, the REST layer behind supabase-js, answers 503.
Other class 08 errors
- 08006 connection failure / server closed the connection unexpectedly