OperationalError: too many connections
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