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

Jim Hogue jjhogue at sbcglobal.net
Tue Mar 13 15:27:20 EDT 2007

I just got a copy of "Rails Recipes" and I see in the index

    15. Connecting to Multiple Databases

I literally just got the book, so I can't give you any details, but 
this might help get you to a solution.

Note that the OT comment is probably correct as it is Rails, not 
Mongrel that deals with the database.  You may want to try the Rails 
mailing list archives.

    - Jim

----- Original Message ----- 
From: "Steve Midgley" <public at misuse.org>
To: <mongrel-users at rubyforge.org>
Sent: Tuesday, March 13, 2007 1:00 PM
Subject: Re: [Mongrel] Mongrel cluster with one app and many mysql 

> Hi,
> 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
> investigate.
> 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:
> config.database_configuration["development"]["database"]
> 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,
> Steve
> 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


> _______________________________________________
> Mongrel-users mailing list
> Mongrel-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-users 

More information about the Mongrel-users mailing list