# Using multiple databases

**URL:** <https://www.ruby-forum.com/t/using-multiple-databases/178023>\
**Category:** Rails\
**Created:** [October 28, 2009, 5:12am UTC](https://www.ruby-forum.com/t/using-multiple-databases/178023 "2009-10-28T05:12:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [October 28, 2009, 5:12am UTC](https://www.ruby-forum.com/t/using-multiple-databases/178023/1 "2009-10-28T05:12:01Z")

</div>

Dear Frienz,

In one of my project i need to implement archiving of logs.

I have two database called people\_development and archive\_development. I  
have used all my development in people\_development database.

development:  
adapter: mysql  
database: people\_development  
host: localhost

I have used reports about people like their attendences in logs module.  
So daily atleast 100s of reports will be updated in the database. Now i  
need to implement archiving of such logs into another database like  
archive\_development.

How this could be done in rails? I need to do the same manually, ie my  
application should have option to move selected logs to archive  
database.

Could any one plz suggest on this?

Thanks in advance,

Regards,  
Rose Martin

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [October 28, 2009, 2:15pm UTC](https://www.ruby-forum.com/t/using-multiple-databases/178023/2 "2009-10-28T14:15:07Z")

</div>

dare ruby wrote:

> Dear Frienz,
> 
> In one of my project i need to implement archiving of logs.
> 
> I have two database called people\_development and archive\_development. I  
> have used all my development in people\_development database.
> 
> development:  
> adapter: mysql  
> database: people\_development  
> host: localhost
> 
> I have used reports about people like their attendences in logs module.  
> So daily atleast 100s of reports will be updated in the database. Now i  
> need to implement archiving of such logs into another database like  
> archive\_development.
> 
> How this could be done in rails? I need to do the same manually, ie my  
> application should have option to move selected logs to archive  
> database.

Rails will deal with multiple databases. But why do you need a separate  
DB for your archives? That seems pointless. You should just be able to  
put the archive table in the same DB. That’s if you even _need_ an  
archive table – you may not.

> Could any one plz suggest on this?
> 
> Thanks in advance,
> 
> Regards,  
> Rose Martin

## Best,

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

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [October 29, 2009, 7:58am UTC](https://www.ruby-forum.com/t/using-multiple-databases/178023/3 "2009-10-29T07:58:33Z")

</div>

Thanks maren for your suggestion

> Rails will deal with multiple databases. But why do you need a separate  
> DB for your archives? That seems pointless.

I need to reduce the huge load in the same db and i want the archives in  
a seperate DB so that i can take regular backups seperately the live  
content and archived content.

> You should just be able to  
> put the archive table in the same DB. That’s if you even _need_ an  
> archive table – you may not.

I have a controller logs, a models student\_logs and methods like list  
and archive.

When i call list page, the page should fetch lists of logs from  
student\_logs table, i have option to select all those logs now i need to  
move these selected logs into another database. I have used the method  
archive to do this under logs controller.

I have used active\_delegate plugin, but my list page itself fetches  
record from the archive database and not from original database. I need  
to list logs from original database and need to move the selected logs  
to archive database.

In model i have used ,

delegates\_connection\_to :archive\_log, :on =\> [:archive]

and in database.yml file i have,

development:  
adapter: mysql  
host: localhost  
database: people\_development

archive\_log:  
adapter: mysql  
host: localhost  
database: archive\_development

So the using the above i was not able to the same, Could anyone please  
suggest on the above scenario. Is it possible to do using  
active\_delegate or is there any other plugin which satisfies my  
requirement.

Thanks in advance

Regards,  
Jose martin

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [October 29, 2009, 1:43pm UTC](https://www.ruby-forum.com/t/using-multiple-databases/178023/4 "2009-10-29T13:43:45Z")

</div>

dare ruby wrote:

> Thanks maren for your suggestion
> 
> > Rails will deal with multiple databases. But why do you need a separate  
> > DB for your archives? That seems pointless.
> 
> I need to reduce the huge load in the same db

I don’t see why. Tables are pretty much independent when it comes to  
load.

> and i want the archives in  
> a seperate DB so that i can take regular backups seperately the live  
> content and archived content.

I _think_ you can do this with one DB, but I might well be wrong.

## Best,

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

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [October 30, 2009, 4:34am UTC](https://www.ruby-forum.com/t/using-multiple-databases/178023/5 "2009-10-30T04:34:55Z")

</div>

I _think_ you can do this with one DB, but I might well be wrong.

Thanks marnen for your support.

I fixed this issue by using establish\_connection where ever necessary to  
switch my database. It works fine with establish\_connection method.

Thanks

Regards,  
Martin
