Skip to content

cdfrm/magento2-splitdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magento 2 DB Split (Master - Slaves architecture)

CodeFarm_SplitDB

"Supported Magento Version" "Latest Release"

Magento 2 CE Split Database to Master and Slave

  • Compatible with Magento Open Source 2.3.x & 2.4.x

Features

This module provides the ability to route query from Frontend to specific MySql instance (write to master and select to slave). The module currently provides the following advantage:

  • Increasing performance of Frontend Store
  • Prevent MySql server from deadlock (SQLSTATE[40001]: Serialization failure: 1213 Deadlock)
Example Config

Example Config

You need to change your enviroment config file - env.php.

Old config:

Screenshot from 2021-12-31 17-24-13

New Config:

Screenshot from 2021-12-31 17-25-16

  • To quick disable split database and route all query to master: bin/magento db:mode:set default
  • To quick enable split database and route all query to master: bin/magento db:mode:set split

If you not config, default connection will be used.

Requirements

  • Magento Open Source version 2.3.x or 2.4.x

Installation

Please install this module via Composer. This module is hosted on Packagist.

  • composer config repositories.nosense '{"type": "composer","url": "https://repo.nosense.lol"}'
  • composer require cdfrm/magento2-splitdb
  • bin/magento module:enable CodeFarm_SplitDb
  • bin/magento setup:upgrade

Testing

You can add log to check at: \CodeFarm\SplitDb\Adapter\Pdo\Mysql::query Screenshot from 2021-12-31 17-37-09

Update:

use for all frontend and admin. All query after Write Query will be route to Write instance. (This will prevent latancy of Master-Slave architechture (Some performance traded here :D))

Licence

GPLv3 © Pham Dai