# Multi\_db

**URL:** <https://www.ruby-forum.com/t/multi-db/168893>\
**Category:** Rails\
**Created:** [May 27, 2009, 6:07am UTC](https://www.ruby-forum.com/t/multi-db/168893 "2009-05-27T06:07:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [May 27, 2009, 6:07am UTC](https://www.ruby-forum.com/t/multi-db/168893/1 "2009-05-27T06:07:29Z")

</div>

I would like to use the multi\_db gem to connect to multiple slave  
databases. It looks pretty easy as long as your app has a single  
application database. For example:  
production:  
adapter: mysql  
database: a\_production  
username: blahblah  
password:  
host: 10.0.0.1  
port: 3306

production\_slave\_database\_1:  
adapter: mysql  
database: a\_production  
username: blahblah  
password:  
host: 10.0.0.3  
port: 3306

production\_slave\_database\_2:  
adapter: mysql  
database: a\_production  
username: blahblah  
password:  
host: 10.0.0.4  
port: 3306

The issue I am having is I can’t figure out how to configure it to  
work with multiple application databases. Let’s say your app has 2  
databases, your main app database and data database. The app database  
has users info and user created info while the data database has a lot  
of read only data that gets updated say…once a week.

You might create a  
production:  
adapter: mysql  
.  
.  
.  
production\_data:  
adapter: mysql  
.  
.  
.

Then you might want slave/s for each of those databases. You can use  
establish\_connection in the models that need to access the  
production\_data database. There is a way to do it with masochism like  
this:

##example, showing the setup of a different master/slave combo using  
setup\_for  
config.after\_initialize do  
ActiveReload::ConnectionProxy.setup!  
ActiveReload::ConnectionProxy.setup\_for SpeciesSchemaWriter,  
SpeciesSchemaModel  
end  
But, as far as I know you can only use a single slave with masochism,  
is that true?

Thanks for any help.  
Erik
