ERROR 1206 (HY000): The total number of locks exceeds the lock table size means one InnoDB transaction tried to lock so many rows that its lock structures no longer fit in the memory InnoDB allows for them. There is no separate "lock table size" setting to raise. The locks live in the buffer pool, and the real fix is almost always to make the transaction smaller.
mysql> DELETE FROM events WHERE created_at < '2025-01-01';
ERROR 1206 (HY000): The total number of locks exceeds the lock table size
The server error reference lists it as error 1206, symbol ER_LOCK_TABLE_FULL, SQLSTATE HY000. Two things make it painful. It usually arrives minutes or hours into a long statement, and the work done so far is undone, because InnoDB rolls back the whole transaction, not just the last statement (you can see this in row0mysql.cc, where DB_LOCK_TABLE_FULL is handled the same way as a deadlock).
Where the "lock table" actually lives
InnoDB stores row locks compactly: a record lock structure carries a bitmap for one index page, so a single structure can cover many rows on that page. Those structures are allocated in a per-transaction memory heap, and when the heap grows, its blocks are taken from the buffer pool.
The cut-off is a heuristic in buf0lru.cc, the function buf_LRU_buf_pool_running_out(). It returns true when the pages on the free list plus the LRU list fall below a quarter of a buffer pool instance. In plain words: once lock memory and other internal users of the pool (the adaptive hash index, for example) hold about three quarters of an instance, InnoDB stops granting new row locks to big writers and returns 1206. The source comment states the purpose directly: to prevent huge transactions from eating up the whole buffer pool for their locks.
The check runs when a transaction that already holds more than 10,000 lock structures sets another record lock while reading rows, which is how UPDATE, DELETE and locking reads (SELECT ... FOR UPDATE / FOR SHARE) find their rows. It also runs before inserts and updates that have to reorganise the index tree. That is why the error hits bulk statements and almost never shows up in normal OLTP traffic.
What usually triggers it
- A small buffer pool. The default is 128 MB. Servers that were never tuned, containers and small cloud instances hit 1206 on statements that a properly sized server would finish without complaint. Our guide to sizing the InnoDB buffer pool covers how to pick a value.
- One statement over millions of rows.
DELETE FROM events WHERE created_at < ...orUPDATE ... SET flag = 1on a whole table, run as one transaction. - No usable index. The InnoDB locking documentation says that if MySQL must scan the entire table, every row of the table becomes locked.
UPDATEandDELETEset next-key locks on every record the search encounters, whether or not theWHEREcondition later excludes it. INSERT ... SELECTunder REPEATABLE READ. Under the default isolation level InnoDB sets shared next-key locks on the rows it reads from the source table, as well as locks on every row it inserts. Copying a large table in one statement doubles the lock count.
How to see it coming
From a second session, while the statement runs, look at information_schema.INNODB_TRX. The documentation describes trx_lock_structs as the number of locks reserved, trx_lock_memory_bytes as the memory taken by the transaction's lock structures, and trx_rows_locked as an approximate count of locked rows.
-- run from a second session while the big statement is still going
SELECT trx_mysql_thread_id,
trx_started,
trx_lock_structs,
ROUND(trx_lock_memory_bytes/1024/1024) AS lock_mb,
trx_rows_locked,
trx_rows_modified
FROM information_schema.INNODB_TRX
ORDER BY trx_lock_memory_bytes DESC
LIMIT 5;
-- and compare with the buffer pool size
SELECT @@innodb_buffer_pool_size/1024/1024 AS buffer_pool_mb;
SHOW ENGINE INNODB STATUS shows the same thing in the TRANSACTIONS section, one line per transaction:
-- example output
---TRANSACTION 4211897, ACTIVE 312 sec fetching rows
mysql tables in use 1, locked 1
48211 lock struct(s), heap size 5537912, 9874310 row lock(s)
If the heap size keeps growing and is getting close to three quarters of a buffer pool instance, the statement will fail. Stopping it early saves you the rollback of the part that has not been done yet.
How to fix it
- Split the change into batches. This is the fix that works on every server. Each batch is its own short transaction, so its locks are freed at commit. Walk the primary key, keep batches in the low thousands of rows and stop when a batch affects zero rows.
-- delete by primary key range, one short transaction per batch -- (assumes an index on created_at and an AUTO_INCREMENT id) SET @max_id := (SELECT MAX(id) FROM events WHERE created_at < '2025-01-01'); DELETE FROM events WHERE id <= @max_id AND created_at < '2025-01-01' ORDER BY id LIMIT 5000; -- repeat until ROW_COUNT() = 0, with a short pause between batches - Give the statement an index. If the
WHEREcolumn is not indexed, InnoDB locks every row it scans. With an index oncreated_atit only locks the range it reads. - Use READ COMMITTED for the job's session. The isolation level documentation says that under READ COMMITTED, record locks for non-matching rows are released after the
WHEREcondition is evaluated, andINSERT ... SELECTreads the source table as a consistent read without locks. The catch: only row-based binary logging is supported with READ COMMITTED, so checkbinlog_formatfirst.-- only for this session; requires row-based binary logging SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; INSERT INTO events_archive SELECT * FROM events WHERE created_at < '2025-01-01' AND id BETWEEN 1 AND 500000; - Increase the buffer pool, if it is undersized anyway.
innodb_buffer_pool_sizecan be changed at runtime. Per the resizing documentation, the resize waits for active transactions to finish and blocks other threads during some steps, so do it in a quiet period. A bigger pool only moves the limit, so batch the job as well.-- dynamic; the value is rounded to a multiple of -- innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances SET GLOBAL innodb_buffer_pool_size = 8 * 1024 * 1024 * 1024; SHOW STATUS LIKE 'Innodb_buffer_pool_resize_status%';
What does not help: searching for a lock table size setting. There is no separate parameter for it. Raising innodb_lock_wait_timeout does nothing either, because 1206 is about memory, not about waiting.
On large production databases
On a small test copy the same statement finishes in seconds and never comes close to the limit, so 1206 tends to appear for the first time in production. A few things matter at that scale:
- The rollback can be as slow as the work. In our experience, rolling back a transaction that changed tens of millions of rows takes about as long as making the change, sometimes longer, and the rows stay locked until it finishes. A planned batch job is far cheaper than a failed single statement.
- Size the batch from measurements. Run one batch on a production-sized copy, check
trx_lock_memory_bytesand the run time, then pick a size that keeps each transaction to a second or two. Rows on one page can share a lock structure, so wide rows and scattered keys use more lock memory per row than narrow, sequential ones. - Watch undo and the history list. Even a batch job that never hits 1206 can create a long undo backlog if a long-running read holds an old snapshot. Check
History list lengthbetween batches; our article on InnoDB history list length explains what to do when it climbs. - Replicas apply what the source commits. In our experience, one giant transaction reaches the replica as one giant event group and the replica falls behind for about as long as the statement ran. Small batches with a pause between them keep lag flat.
- Alert before it fails. A check on
MAX(trx_lock_memory_bytes)fromINNODB_TRX, plus long-running transaction age, warns you about a runaway job long before it errors out and rolls back. - Prefer partitions for retention. If you delete old data every month, a table partitioned by date lets you drop a whole partition instead of deleting rows one by one, and there are no row locks to run out of.
Key takeaways
- 1206 means a single transaction's row locks no longer fit in the part of the buffer pool InnoDB allows for them, about three quarters of an instance.
- The whole transaction is rolled back, not only the last statement.
- There is no lock table size parameter. Batch the change, add an index, or use READ COMMITTED with row-based binlog.
- A 128 MB default buffer pool makes 1206 far more likely. Resize it, but still batch.
- On big tables, plan for rollback time, undo growth and replica lag, and monitor
trx_lock_memory_bytes.