You can configure a reader database in Matomo by editing your config file in
config/config.ini.php and configuring the reader like this:
host = example.host
username = example_user
password = example_password
dbname = example_db_name
port = 3306
aurora_readonly_read_committed = 0
For this to work, you first need to setup database replication in your MySQL or MariaDB database.
We recommend to only configure a reader if you can ensure there is a minimal replication lag / delay on the reader. Otherwise you might get corrupt/outdated data in the reports.
If configured, the following queries will be executed on the reader (slave) instead of the writer (master):
- archiving queries that hit a log table
- live queries that hit a log table
Please note that when you are configuring a reader and are using custom plugins that add new reports (that have a custom archiver), these plugins need to make sure to make use of the reader as otherwise queries will fail. All plugins from Matomo / InnoCraft are compatible. Most third party plugins are automatically compatible as well.
If you are using Amazon Aurora you can enable aurora_read_only_read_committed to prevent purge lag which happens when internal garbage collection is blocked by long-running archiving queries. The setting will be only applied if you have configured a reader database.