79468543

Date: 2025-02-26 04:42:19
Score: 1.5
Natty:
Report link

I faced with memory leak issue with one queryset. In my case solution was to get only fields that I want to use with QerySet.values(*fields) together with QuerySet.iterator(). But there is a limitation of usage iterator. In accordance with this article, if you use a connection pooler (like PgBouncer, I believe it is just a question of time when DB should start to use it) in transaction mode, you should pay attention that during new transaction DB cursor of previous transaction is not available. So QerySet.iterator() probably will fail with error in such case unless you wrap it with transaction.

Also in my situation I stumbled with ridiculous situation when QuerySet.iterator() did not helped and there was still huge memory consumption. Two days of investigation shown that in DB connection settings DISABLE_SERVER_SIDE_CURSORS was set to True and django just did not use DB cursors. I just removed it and everything started to work as expected.

Reasons:
  • Blacklisted phrase (1): this article
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Vlad Farsiyants