Opened 5 years ago

Closed 5 years ago

#21245 closed Cleanup/optimization (duplicate)

Long-running process with many SQL operations crashes when DEBUG is True

Reported by: Patrick Paul Owned by: nobody
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When DEBUG=True, SQL queries are buffered in memory and for long-running processes this can cause the server to kill the process.

In my particular use case, I was crashing when executing a South data migration which ingested large datasets into my PostGIS database.

There is a monkey patch available on SO:

After including this monkey patch in each of my data migration files, the migrations completed successfully.

Here is why I am creating an issue:
1) There isn't a very helpful message when the process is terminated; you have to deduce it from looking at PostgreSQL logs or /var/log/syslog to see that low memory was the perpetrator.
2) There is no way to configure in to disable the CursorDebugWrapper (e.g. settings.DISABLE_DEBUG_CURSOR boolean)
3) I wonder if we can't make Django smart enough to trap Out-of-memory errors to present an informative exception via Python and/or...
4) ...smartly manage the connection.queries buffer to prevent it from using too much RAM in the first place?

N2 would be an easy pickings solution (here:, but it wouldn't solve N1 and developers might not know that RAM is the issue. So I think N3/N4 should be considered.

Change History (1)

comment:1 Changed 5 years ago by Claude Paroz

Resolution: duplicate
Status: newclosed

Duplicate of #12581

Note: See TracTickets for help on using tickets.
Back to Top