MariaDB / Editorial solution guide
Diagnose a MariaDB metadata-lock wait
Identify the blocking transaction and protect the migration boundary before changing sessions or timeouts.
Read-only knowledge base · No public comments
Recognize the symptoms
An ALTER TABLE or other schema operation waits for a metadata lock, eventually times out, or causes later work to queue. The application may report ERROR 1205 (HY000), but the same broad timeout text needs context: capture the statement stage and actual wait evidence before deciding that metadata locking is responsible.
Understand the likely causes
- A transaction that has used a table can retain a metadata lock until the transaction ends. A schema change needing an incompatible lock can wait behind it. Long application transactions, idle sessions with open transactions, or related objects can therefore affect a migration. Availability of lock instrumentation and its privileges depend on MariaDB version and configuration.
Capture the waiting operation
Record the server version, affected schema and object, migration statement, start time, application impact, and authorized session identifiers. Compare the wait with deployment history and long-running transactions. Do not copy sensitive SQL literals or credentials into shared evidence. Determine whether the operation is still waiting or is performing work; a slow schema change can have causes other than a metadata lock.
Inspect held and requested locks
Where already enabled and authorized, inspect Performance Schema metadata_locks and correlate its owner thread with the relevant session and transaction. The table is available from MariaDB 10.5.2, but missing rows do not prove the absence of locks if instrumentation or visibility is unavailable. The illustrative query below filters one synthetic lab object; it changes no settings and makes no assumption about the output.
SELECT OBJECT_SCHEMA, OBJECT_NAME, LOCK_TYPE, LOCK_DURATION, LOCK_STATUS, OWNER_THREAD_ID
FROM performance_schema.metadata_locks
WHERE OBJECT_SCHEMA = 'harbor_lab' AND OBJECT_NAME = 'shipments';
Read held and requested locks for the named lab object when the table and instrumentation are available. Correlating an owner thread to a session requires additional authorized evidence; the rows are environment-dependent.
Resolve the evidenced blocker safely
Identify the owner and purpose of the transaction, and use the established operational procedure to complete or roll it back when appropriate. Do not terminate an arbitrary session or change a global timeout merely to make the migration proceed; either action can interrupt business work or obscure the cause. If instrumentation must be enabled, assess its availability and operational impact separately under the deployment’s procedure. Rehearse the change and its recovery path on representative isolated data.
Verify migration and application recovery
Observe that the waiting operation finishes or is safely stopped, and check its actual result and schema definition. Confirm that application requests and transaction cleanup return to normal, then inspect replica progress where applicable. Repeat the migration rehearsal with a deliberately long transaction to test monitoring and the stopping condition. Document transaction ownership and alert on prolonged waits so the same blocking pattern can be addressed before the next release.
Verify the fix
The relevant metadata wait clears and the migration outcome and resulting schema match the approved procedure.
Application operations, transaction cleanup, and replica progress recover over an observed interval.
Keep it from recurring
- Keep transaction lifetimes deliberate and monitor long transactions and metadata-lock waits.
- Rehearse schema changes under representative concurrent load and define a stopping and recovery plan.