# Seemingly random PostgreSQL connection drops while handling Django requests

**URL:** <https://forum.djangoproject.com/t/seemingly-random-postgresql-connection-drops-while-handling-django-requests/19026>\
**Category:** Mystery Errors\
**Created:** [February 22, 2023, 9:17am UTC](https://forum.djangoproject.com/t/seemingly-random-postgresql-connection-drops-while-handling-django-requests/19026 "2023-02-22T09:17:07Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![lv16](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lv16/32/17122_2.png) [@lv16](https://forum.djangoproject.com/u/lv16)\
**Post date:** [November 17, 2023, 8:26am UTC](https://forum.djangoproject.com/t/seemingly-random-postgresql-connection-drops-while-handling-django-requests/19026/19 "2023-11-17T08:26:51Z")

</div>

Hi!  
Exact same issues here, and some other related:

- `InterfaceError: connection already closed`
- `TransactionManagementError An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.`
- `InterfaceError: cursor already closed`
- `'NoneType' object has no attribute 'cursor'`

My setup:  
- Django 4.1.1  
- Gunicorn 20.1.0 (and then 21.2.0)  
- psycopg2-binary 2.9.3  
- Postgres 14.9 ? (managed)

The 2 non-django native middlewares that I use amongst those mentionned by @lukas-slezevicius are whitenoise (6.5.0) and debug\_toolbar (3.6.0).

I am also using a postgres managed database instead of hosting it locally. I suspected the service provider to be the cause but looking at the thread I’m not really sure anymore.

Since we all got the same gunicorn version I tried upgrading but still same issues.

---

_[View the full topic](https://forum.djangoproject.com/t/seemingly-random-postgresql-connection-drops-while-handling-django-requests/19026)._
