Automatically switch to a read-only database when the master database is unavailable

222 views Asked by At

I am trying to find ways to switch between a Master and Slave database (Postgresql). If the Master is not available then SilverStripe will pick it up and switch databases to the Slave (read-only) database.

I was reading through Sam Minnee's post about it and am wondering if there has been any work done on this? Ideally, this would be an automated action.

1

There are 1 answers

0
Barry On

you could place code in your _config.php like...

global $databaseConfig;

$conn = new mysqli($databaseConfig['server'], $$databaseConfig['username'], $$databaseConfig['password']);
if ($conn->connect_error)
    $otherDB = array(
    "type"      => 'MySQLDatabase',
    "server"    => 'localhost',
    "username"  => 'read_only_user',
    "password"  => 'some_password',
    "path"      => '',
    "database"  => 'other_database'
);