Skip to content

Knowledgebase

Investigating Django database connection exhaustion

development

Too many database connections can prevent new requests from completing even while the server appears otherwise healthy. Count the connections created by all web processes, workers and scheduled jobs.

Gather the details you will need

Record the database connection limit, deployment worker counts and the settings for connection lifetime or pooling. Gather the error time and current database connection observations.

01 Investigate Django database connection exhaustion

  1. Estimate the combined demand from application processes and threads, background workers, administration tools and other applications sharing the database.

  2. Review Django connection settings for the selected backend and execution model. Persistent connections and explicit pools need deliberate limits; ASGI deployments have specific guidance for persistent connection handling.

  3. Look for long-running transactions, blocked queries or workers that retain connections while waiting on unrelated external services.

  4. Reduce unnecessary concurrency or connection lifetime where appropriate, then use a backend-supported pool if it fits the architecture. Leave capacity for maintenance and recovery access.

  5. Repeat a representative load test and observe connection counts, query latency and application error rates together.

Confirm the expected result

Confirm the application operates below the usable connection ceiling during its expected traffic peak and scheduled work. A lower worker count is useful only if requests still complete within acceptable time.

If the problem continues

If connections rise after every deployment, investigate old processes that did not stop. If a few sessions remain blocked, identify the owning query before terminating anything.

A common question

Should I simply increase max_connections?

That can move the bottleneck and consume more database resources. Find the source of demand and size the database and application together rather than treating the limit as an isolated setting.

Was this answer helpful?

Need a little more help?

Our support team can help you find the next step.

Contact support