Login

Custom db backend for statement_timeout support (postgresql_psycopg2)

Author:
gonz
Posted:
April 1, 2010
Language:
Python
Version:
1.1
Score:
1 (after 1 ratings)

Put this in a base.py file.

And config this settings:

DATABASE_ENGINE = 'path.to.module.with.base.file' DATABASE_STATEMENT_TIMEOUT = 60000 # milliseconds

(Idea from: http://www.mailinglistarchive.com/html/[email protected]/2009-02/msg00024.html)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# base.py
from django.db.backends.postgresql_psycopg2.base import *
from django.conf import settings


class DatabaseWrapper(DatabaseWrapper):
    def _cursor(self):
        cursor = super(DatabaseWrapper, self)._cursor()
        statement_timeout = getattr(settings, 'DATABASE_STATEMENT_TIMEOUT', None)
        if statement_timeout is not None:
            cursor.execute("SET STATEMENT_TIMEOUT=%s" % statement_timeout)
        return cursor

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 4 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.