Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The following setup has one master and two slaves with cross failover. If master fails, system will continue in read-only mode. If both slaves fail, system will continue only using the master.
<?php
$databases['default']['master'] = array (
'database' => 'mydatabase',
'username' => 'readwrite',
'password' => 'readwrite',
'host' => 'master',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
);
$databases['default']['slave'][] = array (
'database' => 'mydatabase',
'username' => 'readonly',
'password' => 'readonly',
'host' => 'slave1',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
'readonly' => TRUE,
);
$databases['default']['slave'][] = array (
'database' => 'mydatabase',
'username' => 'readonly',
'password' => 'readonly',
'host' => 'slave2',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
'readonly' => TRUE,
);
$databases['default']['default'] = array (
'driver' => 'autoslave',
'master' => array('master', 'slave'),
'slave' => array('slave', 'master'),
);
?>
Comments
Drupal 8 Master Slave Database Configuration
In Drupal 8 Master-Slave database setup can be configured using the suggestion provided in link: https://www.drupal.org/docs/8/api/database-api/database-configuration. While checking setup in local environment, this approach is not working as per expectation. So there is an alternative snippet which actually worked and tested on Drupal version 8.8.0.