# One rails, multiple DBs

**URL:** <https://www.ruby-forum.com/t/one-rails-multiple-dbs/183248>\
**Category:** Rails\
**Created:** [February 10, 2010, 4:58pm UTC](https://www.ruby-forum.com/t/one-rails-multiple-dbs/183248 "2010-02-10T16:58:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arvias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arvias](https://www.ruby-forum.com/u/arvias)\
**Post date:** [February 10, 2010, 4:58pm UTC](https://www.ruby-forum.com/t/one-rails-multiple-dbs/183248/1 "2010-02-10T16:58:35Z")

</div>

Hi.

I’m in a situation where I have to provide a hosted Rails App  
solution. I’m running Apache with passenger in the backend.

What is the proper way to change the DB depending on the subdomain?  
Should I use data\_fabric?

–  
R.

---

<div class="post-metadata">

**Author:** ![arvias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arvias](https://www.ruby-forum.com/u/arvias)\
**Post date:** [February 10, 2010, 5:05pm UTC](https://www.ruby-forum.com/t/one-rails-multiple-dbs/183248/2 "2010-02-10T17:05:59Z")

</div>

Marcelo B. wrote:

> Hi.
> 
> I’m in a situation where I have to provide a hosted Rails App  
> solution. I’m running Apache with passenger in the backend.
> 
> What is the proper way to change the DB depending on the subdomain?  
> Should I use data\_fabric?

Generally, you don’t need a separate DB for each subdomain. One big DB  
is usually better.

> –  
> R.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![arvias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arvias](https://www.ruby-forum.com/u/arvias)\
**Post date:** [February 10, 2010, 7:00pm UTC](https://www.ruby-forum.com/t/one-rails-multiple-dbs/183248/3 "2010-02-10T19:00:21Z")

</div>

Hi,

> Generally, you don’t need a separate DB for each subdomain. One big DB  
> is usually better.

It’s a high volume app, that’s written as a standalone service.  
Extending it as a hosted solution and keeping updates nice is a big  
part of what the project is about.

–  
Cheers,  
M.

---

<div class="post-metadata">

**Author:** ![arvias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arvias](https://www.ruby-forum.com/u/arvias)\
**Post date:** [February 10, 2010, 7:02pm UTC](https://www.ruby-forum.com/t/one-rails-multiple-dbs/183248/4 "2010-02-10T19:02:48Z")

</div>

Marcelo B. wrote:

> Hi,
> 
> > Generally, you don’t need a separate DB for each subdomain. ï¿½One big DB  
> > is usually better.
> 
> It’s a high volume app, that’s written as a standalone service.  
> Extending it as a hosted solution and keeping updates nice is a big  
> part of what the project is about.

And all of that would be easier with one big DB, at least as far as  
you’ve described.

> –  
> Cheers,  
> M.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![arvias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arvias](https://www.ruby-forum.com/u/arvias)\
**Post date:** [February 10, 2010, 7:35pm UTC](https://www.ruby-forum.com/t/one-rails-multiple-dbs/183248/5 "2010-02-10T19:35:29Z")

</div>

Hi.

> > It’s a high volume app, that’s written as a standalone service.  
> > Extending it as a hosted solution and keeping updates nice is a big  
> > part of what the project is about.
> 
> And all of that would be easier with one big DB, at least as far as  
> you’ve described.

You are right, it would definitely be easier if this App was written  
with a hosted version in mind. Unfortunately it isn’t.

Still, the volume of traffic and DB size of the app means that if  
someone grows bigger we want to be able to quickly move it to  
something dedicated.

–  
Cheers,  
R.

---

<div class="post-metadata">

**Author:** ![arvias](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arvias](https://www.ruby-forum.com/u/arvias)\
**Post date:** [February 10, 2010, 7:52pm UTC](https://www.ruby-forum.com/t/one-rails-multiple-dbs/183248/6 "2010-02-10T19:52:27Z")

</div>

DataMapper out of the box will let you use multiple databases,  
although these need to be known at app boot time.

For ActiveRecord, this article might lead you somewhere:  
[http://tomayko.com/writings/rails-multiple-connections](http://tomayko.com/writings/rails-multiple-connections)

Nathan
