Deadlocks in MySQL

This article talks about deadlocks in MySQL to help identify and resolve them if they cause a site down, stuck database import, or other Adobe Commerce issues.

Affected products and versions

  • Adobe Commerce on-premises 2.2.x and 2.3.x
  • Adobe Commerce on cloud infrastructure 2.2.x and 2.3.x

Issue

Deadlocks in MySQL occur when two or more transactions mutually hold and request for locks. Deadlocks being present do not always indicate an issue but often are a symptom of some other MySQL or Adobe Commerce issue that has occurred.

Often the application, deployment, or MySQL logs will mention a “deadlock” error or the error “Deadlock found when trying to get lock; try restarting transaction.”

Cause

Deadlocks can have multiple causes, but the most common is if you perform any interaction (website/processes/cron jobs/other users/MySQL maintenance/MySQL imports) while performing DML/DDL queries at the same time.

As an example, it is a best practice to avoid a stuck MySQL database import by first putting your site in maintenance mode to avoid getting SQL requests to the database that could cause deadlocks and a stuck database import.

Solution

  1. Check your application, deployment, or MySQL logs for deadlock errors:

  2. Check your MySQL process list for running processes with the command mysql -e 'show full processlist';

  3. If on Adobe Commerce on cloud infrastructure, check that MySQL slave is enabled. Consult this article: Deploy variables (MYSQL_USE_SLAVE_CONNECTION).

  4. Depending on the errors involved, the solution may present itself, or you may need to include your helpful log information if you need to open a Support Ticket.

NOTE
We are aware that this article may still contain industry-standard software terms that some may find racist, sexist, or oppressive and which may make the reader feel hurt, traumatized, or unwelcome. Adobe is working to remove these terms from our code, documentation, and user experiences.
recommendation-more-help
8bd06ef0-b3d5-4137-b74e-d7b00485808a