Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (43 sloc) 1.79 KB
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
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ...,
alter it to:
'default': {
'ENGINE': 'django_pooled',
'NAME': ...,
'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/
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
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.