Diagnosing and Resolving MariaDB InnoDB Lock Wait Timeout Errors
Step‑by‑step guide to diagnose MariaDB InnoDB lock wait timeout errors, check variables, identify blocking transactions, add indexes, adjust timeouts, and decide when to escalate.
07 Oct 2026, 22:54 UTC

Recognizable condition
Applications return ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction when executing UPDATE, DELETE, or INSERT statements under concurrent load. The error indicates that a transaction waited longer than the configured innodb_lock_wait_timeout for a row lock held by another transaction.
Cause and diagnostic overview
| Symptom | Likely cause |
|---|---|
| Frequent timeout errors on hot rows | Long‑running transactions or missing indexes causing full table scans |
| Timeouts appear only under high concurrency | Insufficient innodb_lock_wait_timeout value for the workload |
| Deadlocks appear in the InnoDB status | Lock ordering issues due to application logic |
Ordered checks
Verify the current timeout value. Run this in the MariaDB client as a user with the
PROCESSprivilege:SHOW VARIABLES LIKE 'innodb_lock_wait_timeout';Note the returned value (seconds).
Identify transactions that are waiting or holding locks. Execute:
SHOW ENGINE INNODB STATUS\LATEST DETECTED DEADLOCKLook for the
LATEST DETECTED DEADLOCKsection or theTRANSACTIONSsection that listsWAITING FOR LOCKandLOCK WAITlines. If you have access to the performance_schema, you can also query:SELECT * FROM performance_schema.data_locks WHERE LOCK_STATUS='WAITING' LIMIT 10;This requires the
PROCESSprivilege.Examine the query plan for the statement that triggered the timeout. Replace
your_tableand the WHERE clause with the actual query:EXPLAIN SELECT * FROM your_table WHERE id = 123 FOR UPDATE;Check the
typeandrowscolumns; a value ofALLor a highrowscount suggests a missing index.Assess server load and connection count to see if the system is saturated:
SHOW STATUS LIKE 'Threads_connected';High connection counts combined with long‑running queries can exacerbate lock waits.
Fixes tied to findings
Adjust
innodb_lock_wait_timeout– If the current value is too low for legitimate long‑running transactions, increase it globally (requiresSUPERprivilege):SET GLOBAL innodb_lock_wait_timeout = 120;Verify the change with
SHOW VARIABLES LIKE 'innodb_lock_wait_timeout';. Risk: A higher timeout allows problematic transactions to hold locks longer, potentially increasing contention. Test the new value in a staging environment first.Rollback: Store the original value before changing it, then revert:
SET GLOBAL innodb_lock_wait_timeout = <original_value>;Add missing indexes – If
EXPLAINshows a full table scan, create an appropriate index. Example for a columnstatusused in a WHERE clause:ALTER TABLE your_table ADD INDEX idx_status (status);Verify usage after creation:
EXPLAIN SELECT * FROM your_table WHERE status = 'active';Risk: Indexes increase write overhead and storage consumption. Benchmark the impact on your workload.
Rollback: Drop the index if it proves detrimental:
ALTER TABLE your_table DROP INDEX idx_status;Shorten transaction duration – Refactor application code to commit or roll back as soon as possible. Techniques include:
- Fetching only needed rows.
- Avoiding heavy computations inside a transaction.
- Using optimistic locking or retry logic with exponential backoff.
After changes, monitor
SHOW ENGINE INNODB STATUSfor a reduction ininnodb_row_lock_current_waits.Consider InnoDB tuning options – Enable the adaptive hash index if read‑heavy workloads benefit:
SET GLOBAL innodb_adaptive_hash_index = ON;Or adjust
innodb_thread_concurrency to limit concurrent threads and reduce lock contention.Verify effect by checking
SHOW ENGINE INNODB STATUSfor lower lock wait times.
Escalation criteria
- Lock wait timeouts persist after:
- Increasing
innodb_lock_wait_timeoutto a value that matches your longest legitimate transaction. - Adding indexes that reduce examined rows to a reasonable count (
EXPLAIN rows< 1000 for the problematic query). - Refactoring transactions to be shorter than the new timeout.
SHOW ENGINE INNODB STATUSshows:- Frequent deadlocks (
LATEST DETECTED DEADLOCKappears repeatedly). - High and sustained
innodb_row_lock_current_waits(> 10% ofinnodb_row_lock_time_avg). - Increasing
innodb_lock_waitsdespite timeout adjustments. - If the above conditions hold, consider:
- Reviewing application design for lock ordering (e.g., always access tables in the same order).
- Partitioning hot tables to spread lock contention.
- Upgrading to a newer MariaDB release (e.g., 10.6+) that includes improved InnoDB lock handling and performance_schema enhancements.
Verification
- After changing
innodb_lock_wait_timeout, run: - After creating an index, confirm the plan uses it:
- During a representative load window, monitor:
SHOW VARIABLES LIKE 'innodb_lock_wait_timeout';
EXPLAIN SELECT … WHERE indexed_column = …;
SHOW ENGINE INNODB STATUS\G
Look for decreasing values in innodb_row_lock_current_waits and zero occurrences of Lock wait timeout exceeded in the application logs.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.