I'm looking at a way of achieving fail over and additionally load balancing over three databases in my Rails application.
The code that follows currently works with no issues, however if db_1 is down then my application dies.
I would like to use db_1 as the primary and the other two db_2 and db_3 as a fail over.
Additionally I would like to load balance them but that is a less important requirement.
config/database.yml
db_1:
adapter: mysql2
reconnect: false
pool: 5
username: <username>
password: <password>
database: database_test
host: 101.101.101.1
db_2:
adapter: mysql2
reconnect: false
pool: 5
username: <username>
password: <password>
database: database_test
host: 101.101.101.2
db_3:
adapter: mysql2
reconnect: false
pool: 5
username: <username>
password: <password>
database: database_test
host: 101.101.101.3
app/models/ext_databases.rb
class ExtDatabases < ActiveRecord::Base
self.abstract_class = true
establish_connection :db_1
end
app/models/users.rb
class Users < ExtDatabases
Users.table_name = "ext_users"
end