views:

116

answers:

3

What is a way to handle database unavailability and redirect queries from unavailable slave to another one in Django 1.2?

Btw, i found out, that it was discussed: http://code.djangoproject.com/wiki/MultipleDatabaseSupport#Requirements (see "Transparently handling database failure")

UPD> I use PostgreSQL backend (probably will use pg pool or some other potgres cluster) under linux

+3  A: 

If you are using a PostgreSQL backend and are on a Linux/BSD etc. system, consider using pgpool: http://pgpool.projects.postgresql.org/ This utility handles the connections to the DB server for you, so you only connect to pgpool. No need for you to implement any more logic. Just connect to pgpool, not to PostgreSQL itself.

mawimawi
Hm, thx, i'll look deeper into this. What about django configuration? Can pgpool be used with psycopg just as a normal PostgreSQL database?
DataGreed
@DataGreed - yes pgpool listens on a different port, that's all. Your Django project uses this port, so pgpool works as a transparent proxy to the db.
mawimawi
thank you, mawimawi
DataGreed
A: 

There's also a proxy for MySQL, MySQL Proxy. You would connect to the proxy, and that proxy would know how to handle failover. In the case of MySQL Proxy, it is designed for failover, so I expect it to be both stable and knowing how to handle failures:)

extraneon
+2  A: 

Unfortunately, at the moment there's no way to use the DATABASE_ROUTERS feature in order to handle an unavailable database, you'll have to use an external tool as others have suggested.

Alex Gaynor