Hey folks,
We recently migrated to Ninja for Async APIs, and we faced issues where connections weren’t being closed by django, leading to connection errors on postgres, with 5.1m Django offers a ConnectionPool layer to use pooling but it doesnt support Async contexts, Psycopg does expose an AsyncConnectionPool
wrapper but django has no option to use it currently.
Looking at the source code, I just need to override pool
method in DatabaseWrapper
and then override load_backend
method in djanggo/db/utils
My question is, is this a good way to override django’s db setup for async connection pooling? are there any unforseen issues we havent taken into account and is there anything else we can do?
Remaining options for us are:
- Celery task which calls
close_old_connections
- use
pg_bouncer
which will manage this for us