Login

Custom db backend for statement_timeout support (postgresql_psycopg2)

Author:
gonz
Posted:
April 1, 2010
Language:
Python
Version:
1.1
Tags:
database timeout backends postgress statment_timeout
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/django-developers@googlegroups.com/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. email backend which use sendmail subprocess by pawnhearts 5 years, 4 months ago
  2. PowerDNS models by diverman 6 years ago
  3. Multiple cache backend by isaidyep 4 years, 8 months ago
  4. TwitterBackend by hameedullah 6 years, 1 month ago
  5. Login with email or username by zeeg 6 years, 9 months ago

Comments

Please login first before commenting.