Is It Possible To Have Two Databases, One For Reading, One For Writing?

Hi,

is there any way to?:

  1. Have 2 database components declared for my application, one pointing to a master database, for writing, and one (or many, ideally) read only replicating databases, for reading only data

  2. Redirect writings automatically to master and readings to replica?

If it is not possible, it would be a great addition. If it possible, please be kind and point me to the right direction :)

Thanks in advanced.

That should be transparent to your application, that is this should be resolved in your database directly or using some middleware software.

What database are you using?

Yeah, the database part is already solved. But how can You know which database to use for readings and with for writings? That’s it, how can activerecord’s find know that it must read from replica and how can save know it must write to master?

You=yii, sorry, I’m posting from a phone computer

What you are looking for is split read/write support. There is an extention for that but I can’t comment on its quality. There is an alternative called MySQL proxy which will sit between your application and the actual db.

Thanks a lot. I’ll give the extension a try.