Skip to main content

Round-robin standbydb router for Django.

Project description

``multidb`` provides two Django database routers useful in master-standby
deployments.


MasterStandbyRouter
-----------------

With ``multidb.MasterStandbyRouter`` all read queries will go to a standby
database; all inserts, updates, and deletes will go to the ``default``
database.

First, define ``STANDBY_DATABASES`` in your settings. It should be a list of
database aliases that can be found in ``DATABASES``::

DATABASES = {
'default': {...},
'standby-1': {...},
'standby-2': {...},
}
STANDBY_DATABASES = ['standby-1', 'standby-2']

Then put ``multidb.MasterStandbyRouter`` into DATABASE_ROUTERS::

DATABASE_ROUTERS = ('multidb.MasterStandbyRouter',)

The standby databases will be chosen in round-robin fashion.

If you want to get a connection to a standby in your app, use
``multidb.get_standby``::

from django.db import connections
import multidb

connection = connections[multidb.get_standby()]


Running the Tests
-----------------

To run the tests, you'll need to install the development requirements::

pip install -r requirements.txt
./run.sh test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-standbydb-router-0.1.tar.gz (3.6 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page