Slave support in D7

ctoomey's picture

I'm an architect working on a project to rebuild our current consumer site, possibly using Drupal, and am new to Drupal and learning as much as I can as fast as I can. I see that one of the things that's been added in D7 is support for master/slave DB configurations, so I wanted to get more info. about that.

I've found in the DB documentation that 1) slave DBs can be specified in the DB configuration (, and 2) that module writers can pass an optional 3rd argument to db_query() to mark queries that are save to send to slaves ( Were there any other slave-related changes made in D7 and if so, what were they?

Since 2) requires code changes to modules, I'm curious how much progress has been made in updating code to mark slave-safe queries. Can anyone speak to the extent to which that's been done in core modules and contrib modules?

And can anyone post sample stats from slave-using installations as to what percentage of queries are seen going to slaves?



Hi, So you are right for

sylv3st3r's picture


So you are right for number 1. And I think there are no changes for slave-related db. So I'm going to answer no 2. What have been done in contrib modules for slave-safe queries. As far as I know. Most contrib modules doesn't bother with such things. Because of many reason. Most of it : There not much who have slave db on their disposal. But some of it, like Views module for example, have slave option.
So rather then hack every contrib modules to target slave for slave-safe queries. I took the liberty of hacking Drupal core. Adding a slave-safe queries check on query function. And it is live actually, working fine ( ). I can't filter out ALL slave-safe queries to go to slave db. But at least I managed to route most of them. I say, about 80% slave-safe queries. I'll post some statistics when I'm able to.

Slave support in core modules?

ctoomey's picture

Can anyone speak to the extent to which core modules have been updated to mark slave-safe queries?



moshe weitzman's picture

See for a way for site builders to redirect all or some SELECT queries to slaves without hacking core.