connection closed PostgreSQL Origin: Data OSI layer 4 · Transport Last updated 15 Oct 2026

server closed the connection unexpectedly — This probably means the server terminated abnormally before or while processing the request.

The connection to PostgreSQL dropped — the server restarted/crashed, a proxy/firewall killed an idle connection, or the backend was terminated.

Exact message you may see server closed the connection unexpectedlyterminated abnormally before or while processing the request
Seen on: PostgreSQL

Meaning

Check the PostgreSQL log at that time: OOM kills, crashes and restarts appear there. Otherwise idle connections were cut by NAT/load balancers.

Common causes

  • Server restart or crash (OOM)
  • Idle connection killed by firewall/NAT/proxy
  • pg_terminate_backend by an admin
  • Network interruption

⚡ Quick fix

  1. Check the PostgreSQL log
  2. Enable TCP keepalives / pool health checks (pre-ping)
  3. Reconnect and retry idempotent work

Detailed fix by platform

PostgreSQL

  1. keepalives_idle=60 in the connection string, or pool_pre_ping=True in SQLAlchemy

How to diagnose

  1. Server log — Restart/crash at that time?
  2. Idle — Was the connection idle long?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

2006 — MySQL ERROR 2006 (HY000): MySQL server has gone away (MySQL)20063D000 — FATAL: database "x" does not exist (PostgreSQL)3D00053300 — FATAL: sorry, too many clients already / remaining connection slots are reserved for non-replication superuser connections (PostgreSQL)53300connection limit for role — FATAL: too many connections for role "x" (PostgreSQL)connection limit for …could not connect — PostgreSQL: could not connect to server / connection refused — Is the server running on host and accepting TCP/IP connections? (PostgreSQL)could not connectHikariCP timeout — HikariPool-1 - Connection is not available, request timed out after 30000ms (Java)HikariCP timeoutmaintenance — Cloud SQL connections dropped during maintenance or failover (server closed the connection) (Google Cloud / Firebase)maintenanceSSL required — server does not support SSL, but SSL was required / no pg_hba.conf entry … no encryption (PostgreSQL)SSL requiredconnectio…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.