Edit in GitHubLog an issue

Magento\ResourceConnections module adds a mechanism to segregate database connections between master and slave database servers based on the request type.

For each master database connection (except the indexer connection) that are configured in db/connection section of app/etc/env.php you can add one slave connection that can be configured in db/slave_connection. Configuration format is the same as db/connection. Slave connection name must be the same as associated master connection name. To enable slave connections for specific resources create a slave connection configuration by adding slave_connection node as below:

Copied to your clipboard
1<?php
2return array (
3 //...
4 'db' =>
5 array (
6 'connection' =>
7 array (
8 'default' =>
9 array (
10 'host' => 'default-master-host',
11 'dbname' => 'magento',
12 'username' => 'magento',
13 'password' => 'magento',
14 'active' => '1',
15 ),
16 ),
17 'slave_connection' =>
18 array (
19 'default' =>
20 array (
21 'host' => 'default-slave-host',
22 'dbname' => 'magento',
23 'username' => 'read_only',
24 'password' => 'password',
25 'active' => '1',
26 ),
27 ),
28 'table_prefix' => '',
29 ),
30 //.......

To add slave connection for resources other than 'default' repeat the step and add to db/slave_connection new element with same name and slave configuration for specified resource. Config structure retains backward compatibility if module is turned off.

WARNING: 'indexer' connection is not designed to have slave configuration.

Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.