#33497: Database persistent connection do not work with ASGI in 4.0
-----------------------------------------+--------------------------------
Reporter: Stenkar | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Keywords: ASGI; Database
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+--------------------------------
Hello!
I've discovered that after upgrading Django to ver. 4 (currently 4.0.2), I
started to see database **FATAL: sorry, too many clients already** errors
in the Sentry.
For a database, I'm using containerized Postgres 14.1 and the connection
between Django and Postgres is done by Unix socket.
Database settings look like this:
{{{
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": environ.get("POSTGRES_DB"),
"USER": environ.get("POSTGRES_USER"),
"PASSWORD": environ.get("POSTGRES_PASSWORD"),
"HOST": environ.get("POSTGRES_HOST"),
"PORT": environ.get("POSTGRES_PORT"),
"CONN_MAX_AGE": 3600
}
}
}}}
In production, I'm using ASGI (Uvicorn 0.17.4) to run the Django
application (4 workers).
When everything is deployed and I have surfed around the Django admin
site, then checking Postgres active connections, using **SELECT * FROM
pg_stat_activity;** command, I see that there are 30+ Idle connections
made from Django.
After surfing more around the admin site, I can see that more Idle
connections have been made by Django.
It looks like the database connections are not reused. At one point some
of the Idle connections are closed, but then again more connections have
been made when more DB queries are made by Django.
I have one Django 3.2.11 project running on production and all the
settings are the same, there are always max 10 persistent connections with
the database and everything works fine.
Should that be like this in version 4.0?
--
Ticket URL: <https://code.djangoproject.com/ticket/33497>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.cd8a93fa411f30a0a0ed14a90b06b2c0%40djangoproject.com.