Custom db backend for statement_timeout support (postgresql_psycopg2)

 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. Persistent connection to PostgreSQL database by mike_tk 3 years, 9 months ago
  2. Server Side Cursors for Django's psycopg2 Backend by ryanbutterfield 2 years, 3 months ago
  3. heroku postgress django settings by grillermo 11 months, 1 week ago
  4. PostgreSQL ON DELETE CASCADE by mjt 3 years, 7 months ago
  5. django-techblog fields.py for use with postgresql by dhmorgan 2 years, 11 months ago

Comments

(Forgotten your password?)