I running a script that uses Django ORM. The script runs for long time sometimes more than three days. Script looks like below
from app.models import *
for i in some_simpe_select():
more_simple_selects()
processing_for_few_minutes()
new_object.save()
There are multiple instances for same script running simultaneously with slightly different options. We use postgresql. Over the time this causes DB CPU to go high. ps shows postgres processes idle in transaction but CPU usage unusually high.
I wonder what are best practices around long running django scripts, particularly around high db CPU usage.
Django 1.4, Python 2.7, Postgresql 9.1