Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Python
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
psycopg2
.gitignore
README
__init__.py
base.py

README

This is a very experimental database connection pooling implementation for
Django. The pool requires Django's master/HEAD.

Usage is simple. When you have currently this in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': ...,
    },
    ...
}

alter it to:

DATABASES = {
    'default': {
        'ENGINE': 'django_pooled',
        'NAME': ...,
        'OPTIONS': {
            'WRAPS': 'django.db.backends.sqlite3',
        }
    },
    ...
}

There is a separate implementation for psycopg2. Using this is even simpler,
just set django_pooled.psycopg2 as ENGINE and everything should just work.

There is one additional setting you can define in OPTIONS:
ON_CONNECT -> String which defines what SQL to run on connections fetched
from the pool. The SQL is run to make sure the connection is actually
working. The default is "SELECT 1". The ON_CONNECT can also be a callback,
the arguments are the candidate connection and the Pool. See psycopg2/base.py
for example.

If the execution of the ON_CONNECT string or the callback raises any kind of
exception, the connection is assumed to be in erroneous state and it is
discarded. Otherwise the connection is deemed ready to be used by the
client.

On disconnect rollback is called, nothing else is done.

The Django's test suite is passing on all core backends (on Oracle
you need to use ON_CONNECT = SELECT 1 FROM DUAL). Gis backends aren't
yet tested.

The pool will check all connections at most once in 10 seconds. The check
happens only on taking a new connection. Those connections which haven't
been used in 10 seconds are closed and removed from the pool.

The pooler is still missing some essential features - logging, many config
options and so on.

Note that this implementation isn't meant for production use.
Something went wrong with that request. Please try again.