DjangoKubernetes

Django QuerySet full result caching causes OOM in batch processing

critical
Resource ContentionUpdated Mar 11, 2026(via Exa)
How to detect:

Management command looping through QuerySet with 400k+ rows caused OOM kill when memory usage grew from within 512MB limit to 1.8GB. Django's QuerySet caching loads all results into memory before iteration. Memory consumption scales with result set size.

Recommended action:

Modify QuerySet to prevent full result caching by adding a specific method call that enables streaming of results. Document indicates a single queryset method prevents memory accumulation when processing large datasets.