[Mongrel] Mongrel cluster with one app and many mysql databases

Steve Midgley public at misuse.org
Tue Mar 13 13:00:13 EDT 2007


This is getting a little OT but I think you can easily switch your 
database connections by playing with which environment you're running 
in when the rails system starts up. This doesn't get you all the way to 
your solution but should point out the line of code you'll want to 

For example, if you were to start up 10 scratch Rails instances and had 
10 entries in your database.yml file, one for each configuration, you 
could load 10 different db instances: for each one you would provide a 
different "RAILS_ENV" environment variable (corresponding to the 
appropriate entry in database.yml). Then you'd be running 10 different 
production instances with 10 dif. connections.

What you want is a little trickier b/c you want to switch db instances 
on the fly with a single instance of Rails. But I still don't think 
this is going to be too difficult. For example, it's possible access an 
alternate database configuration entry with this line of code in the 
environment.rb file:


How and where to make the switch in an active running Rails server, I 
don't know, but it looks very plausible.

I hope this helps get you started,


At 09:46 AM 3/13/2007, mongrel-users-request at rubyforge.org wrote:
>Message: 7
>Date: Tue, 13 Mar 2007 14:15:40 +0100
>From: Jens Carroll <jens.carroll at carroll.de>
>Subject: Re: [Mongrel] Mongrel cluster with one app and many mysql
>         databases
>To: mongrel-users at rubyforge.org
>Message-ID: <45F6A3FC.4050605 at carroll.de>
>Content-Type: text/plain; charset=ISO-8859-1
>Thanks Alexey,
>I got also more and more to the point where it is clearly not a 
>Thanks for the answer, but if someone has done that before I would
>really appreciate any pointer.
>Alexey Verkhovsky schrieb:
> >> convince mongrel (or the app) to switch databases on request 
> (maybe
> > with the rails routing facilities)
> >
> > 10 databases with the same structure but different data? This is 
> doable.
> > You'd have to hack it yourself, probably by replacing 
> ActiveRecord::
> > Base.connection with something that will internally hold 10 
> connections
> > and switch dynamically.
> >
> > None of will have anything to do with Mongrel though. Mongrel is 
> not a
> > J2EE container, it has no notion of database connections.
> >
> > Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20070313/a4aebad3/attachment.html 

More information about the Mongrel-users mailing list