2π
I donβt think Django or geodjango offer any support for killing queries that take too long.
A quick search on the postgresql docs gave me the following:
http://www.postgresql.org/docs/9.3/static/runtime-config-client.html#GUC-STATEMENT-TIMEOUT
statement_timeout (integer)
Abort any statement that takes more than the specified number of milliseconds, starting from the time the command arrives at the server
from the client. If log_min_error_statement is set to ERROR or lower,
the statement that timed out will also be logged. A value of zero (the
default) turns this off.Setting statement_timeout in postgresql.conf is not recommended because it would affect all sessions.
But this would affect all queries so you could break other functionality which takes longer for some reason.
The suggested way is to create a special user, e.g. web_user, on the database which runs these queries and limit the time for that user:
ALTER ROLE web_user SET statement_timeout = 10000;
0π
In django, you can implement the statement_timeout
(milliseconds) for a postgresql db in settings.py
like this:
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'username',
'PASSWORD': '',
'HOST': '',
'PORT': '',
'OPTIONS': {
'options': '-c statement_timeout=1000'
}
},
- [Answered ]-Correctly exhibiting date from datapicker
- [Answered ]-How to avoid code duplication with similar Django model methods?
- [Answered ]-Upgrade to Django 1.8.13. Tests fail but app works. Postgresql tables duplicated
- [Answered ]-I have a list of long integers that I assign to a django model charfield. The list of longs get converted to list of unicodes