1638
MariaDBERRORCommonLockingHIGH confidence

Aborted waiting on metadata lock — another connection holds a conflicting lock

Production Risk

High — DDL or DML may be aborted, requiring a retry.

What this means

A statement was aborted because it was waiting for a metadata lock that is held by another connection, and the wait was interrupted (e.g., by KILL or shutdown).

Why it happens
  1. 1A long-running transaction or LOCK TABLES held a metadata lock while another statement waited.
  2. 2The waiting statement was killed or the server was shut down during the wait.
How to reproduce
trigger — this will error
trigger — this will error
-- Session 1: LOCK TABLES t WRITE;
-- Session 2: ALTER TABLE t ADD COLUMN x INT; -- waits
-- Session 1: KILL SESSION 2;

expected output

ERROR 1638 (HY000): Lock wait was interrupted by a higher-priority KILL.

Fix

Identify and close long-running transactions before DDL

Identify and close long-running transactions before DDL
SELECT * FROM information_schema.INNODB_TRX;
KILL <trx_thread_id>;

Why this works

Releasing the blocking transaction frees the metadata lock.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1638 ER_LOCK_ABORTED

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors