Add a read replica
This task is for administrators of busy sites on MySQL or MariaDB. With site.ini [DatabaseSettings] UseSlaveServer=enabled, reads go to a replica chosen at random per request and writes to Server. It is the only
engine with built-in read splitting (Database support; chapter 9, Replicas).
Contents
Before you start
- The database team has set up replication with the vendor's tools; Exponential does not.
- A database user on the replica with read access.
- A change approved and tested on staging.
Steps
In
settings/override/site.ini.append.php(the keys really are spelledSlaver...for the user, password and database):[DatabaseSettings] UseSlaveServer=enabled SlaveServerArray[]=db-replica1.internal.example.gov SlaveServerPort[]=3306 SlaverServerUser[]=<read user> SlaverServerPassword[]=<password> SlaverServerDatabase[]=<database>Clear the INI cache and deploy:
php bin/php/ezcache.php --clear-tag=ini --allow-root-user ./console exp:velocity deploy --allow-root-user
Check it worked
- The site works; publishing still works (writes go to the primary).
- The replica's own query statistics show reads arriving.
- Setup > System information, Database connection, for the connection details as the page shows them.
Limits
- Replication lag: a page may show content a few seconds old; an editor who just published may not see the change at once on a page read from the replica.
- MySQL and MariaDB only; other engines scale reads with their own tools.
- A replica is not a backup and not a failover: if the primary fails, writes fail (Fail over to a standby database).
- The password is in a settings file: keep
settings/overrideout of version control or use your secrets process.
Related pages
- Read replicas
- Database high availability
- Several web nodes (hosting)
- MariaDB for hosts
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.