shaare.it

OperationalError: too many connections

7 Dec 2025

1 min read

OperationalError: too many connections

$ python manage.py runserver
...
OperationalError: FATAL: sorry, too many clients already

Why this happens

Leaking connections or concurrency beyond DB limits.

Fix

Use connection pooling, close cursors, and tune DB max_connections.

Wrong code

for _ in range(1000):
    cursor = connection.cursor()
    # no close

Fixed code

with connection.cursor() as cursor:
    cursor.execute("SELECT 1")
# or reuse ORM, which manages connections