Read replicas
This page is for database administrators in public bodies whose Exponential site runs on PostgreSQL, MySQL, MariaDB or Oracle and who want to move read load off the primary server. It answers how Exponential uses replicas, which settings switch it on, what replication lag means for editors and visitors, and when replicas are worth it. The source is 9.3 MySQL and MariaDB, Replicas.
Contents
What Exponential does with replicas
With UseSlaveServer=enabled, Exponential sends read queries to a replica chosen at random per request; writes go to
Server. Since 6.0.15 PostgreSQL, MySQL, MariaDB and Oracle (ezoracle) follow one rule: only plain SELECTs of
anonymous GET and HEAD requests that have written nothing, and only from a replica that is current; signed-in editors,
forms, cronjobs and scripts read the primary (Read replicas). MongoDB
does not use replicas for reads through this setting, and SQLite has none.
Replicas are a performance feature, not a failover: if the primary fails, writes fail. For availability see Database high availability.
The settings
In settings/override/site.ini.append.php, block [DatabaseSettings]. The keys really are spelled Slaver... for
user, password and database:
[DatabaseSettings]
UseSlaveServer=enabled
SlaveServerArray[]
SlaveServerArray[]=db-replica-1.example.gov
SlaveServerPort[]
SlaveServerPort[]=3306
SlaverServerUser[]
SlaverServerUser[]=<read user>
SlaverServerPassword[]
SlaverServerPassword[]=<password>
SlaverServerDatabase[]
SlaverServerDatabase[]=<database>The host name and placeholders are examples. The shipped settings/site.ini lists these keys commented out, with
UseSlaveServer=disabled. After the change clear the INI cache and make the engine read it:
php bin/php/ezcache.php --clear-tag=ini --allow-root-user
./console exp:velocity deploy --allow-root-userGive the replica user read rights only; it never needs to write. Keep the password out of version control (Configuration under version control).
Replication lag
Before 6.0.15, "replication lag means a page may show content a few seconds old"
(9.3). Since 6.0.15 a replica that lags is not read: MySQL and MariaDB
read it only once it has applied what the primary had committed when the request started (GTID) and is at most
SlaveServerMaxLag seconds behind; Oracle checks the standby's apply lag; PostgreSQL reads only a streaming standby
and closes the window with synchronous apply. Editors always read the primary, so they see their own work at once.
Monitor the lag anyway: a replica that is always behind is simply never read, and the primary carries all the load.
When replicas help
| Situation | Replicas help? |
|---|---|
| Many anonymous visitors | usually not much: Velocity's response cache and the HTTP cache answer them without the database (Velocity response cache and HTTP cache) |
| Uncached pages and searches of anonymous visitors | yes, if the database is the bottleneck |
| Many signed-in users | no: since 6.0.15 signed-in users always read the primary |
| The primary is slow because of writes | no; replicas only take reads |
| You need a standby for continuity | not by themselves; see Database high availability |
Measure before you add a replica: exp:benchmark and the slow query output
([DatabaseSettings] SlowQueriesOutput with SQLOutput=enabled) show where time goes
(Capacity planning).
Checklist
- To do: The site runs on PostgreSQL, MySQL, MariaDB or Oracle (ezoracle).
- To do: MySQL/MariaDB: the replica user has
REPLICATION CLIENT(MySQL) orREPLICA MONITOR(MariaDB) for the status check; Oracle:SELECTonv_$databaseandv_$dataguard_stats; PostgreSQL:pg_read_all_stats. - To do: The replica user has read rights only; its password is not in version control.
- To do: Settings are in
settings/override, the INI cache cleared and the engine reloaded. - To do: Replication lag is monitored, and editors know about the short delay.
- To do: A measurement shows the database was the bottleneck.
Related pages
- Availability index of this folder
- MySQL for hosts, 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.