#35130 closed Cleanup/optimization (fixed)

Document how to manually close database connections

Reported by: Baptiste Mispelon Owned by: Salvo Polizzi
Component: Documentation Version: 5.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I was reading about manual database connection management today and came upon this section (emphasis mine) [1]:

If a connection is created in a long-running process, outside of Django’s request-response cycle, the connection will remain open until explicitly closed, or timeout occurs.

From what I understand, manually closing open db connections is done by calling django.db.close_old_connections(), but that function does not seem to be documented officially.
I'm not sure if the function is undocumented by design (it is after all a pretty unusual use-case and most users should never have to call it themselves), or if that was just an omission.

[1] https://docs.djangoproject.com/en/dev/ref/databases/#caveats

Change History (4)

comment:1 by Mariusz Felisiak, 11 months ago

Triage Stage: UnreviewedAccepted

I think it's fine to at least mention it in the "Caveats" section.

comment:2 by Salvo Polizzi, 11 months ago

Owner: changed from nobody to Salvo Polizzi
Status: newassigned

comment:3 by Mariusz Felisiak, 11 months ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:4 by GitHub <noreply@…>, 11 months ago

Resolution: fixed
Status: assignedclosed

In 184d82d:

Fixed #35130 -- Doc'd django.db.close_old_connections().

This also adds close_db_connections() to the django.db.all.

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