I have one large scale website and hosted on AWS. I want to enable Master-Slave concept on it. How can it be possible to configure the same?


Yes, Drupal supports master/slave style database replication.

Note: master/slave replication configuration is done at the database server level. Drupal simply utilizes the replicated databases by using the slave server when one database isn't available, or for specific 'slave' marked queries ( see db_query "target" option ).

See the fully commented default.settings.php for Drupal configuration details.

For each database, you may optionally specify multiple "target" databases. A target database allows Drupal to try to send certain queries to a different database if it can but fall back to the default connection if not. That is useful for master/slave replication, as Drupal may try to connect to a slave server when appropriate and if one is not available will simply fall back to the single master server.

The general format for the $databases array is as follows:

  • $databases['default']['default'] = $info_array;
  • $databases['default']['slave'][] = $info_array;
  • $databases['default']['slave'][] = $info_array;
  • $databases['extra']['default'] = $info_array;
| improve this answer | |

You may want to try out the AutoSlave module.

This database driver (called "autoslave") will automatically use the database slaves where applicable and otherwise use a master database.

Applicable means:

  • The query is not a write query (and not a select query with locking)
  • The tables in the query have not been written to during the request and within the assumed replication lag
  • A transaction has not been started
  • The tables in the query are not specified in the 'tables' option in the driver settings
  • A lock has not been started (core db-lock and memcache-lock supported)

I'm the author of the module; if you decide to try it out, feedback is appreciated.

| improve this answer | |
  • is there a way to use redis as a cache instead of memcache? – Moses Liao GZ Feb 26 '19 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.