How to fix ERROR 1151: Too many delayed threads in use in MySQL

MySQLINTERMEDIATEMEDIUMUpdated Dec 23, 2025· 93 views

MySQL error 1151 occurs when the number of background INSERT DELAYED threads exceeds the configured limit. This legacy feature is deprecated in modern MySQL versions and typically requires adjusting max_delayed_threads or refactoring to use regular inserts.

Quick fix

Fixes ERROR 1151: Too many delayed threads in use

SELECT VERSION();
  1. Check your MySQL version first
  2. View current delayed insert thread statistics
  3. Increase max_delayed_threads (temporary solution)
  4. Refactor application to use regular INSERT statements
mysql — error
SELECT VERSION();
ERROR 1151: Too many delayed threads in use

What this error means

MySQL Error 1151 (ER_TOO_MANY_DELAYED_THREADS) indicates that the database has reached its maximum limit for concurrent INSERT DELAYED handler threads. INSERT DELAYED is a MySQL feature that allows INSERT statements to be queued and executed in the background, improving application responsiveness during high-traffic scenarios. When too many delayed insert operations are queued simultaneously, MySQL refuses new delayed insert requests to prevent resource exhaustion. This error signals that your delayed insert workload exceeds the configured thread capacity.

Typical symptoms

  • INSERT DELAYED statements fail with error 1151
  • Application receives database connection errors during INSERT operations
  • Application pauses or times out when attempting bulk inserts
  • Error appears in MySQL error log when concurrent inserts spike

Common causes

  1. max_delayed_threads limit is too low for your application workload (default is 20)
  2. INSERT DELAYED statements are being generated faster than they can be processed
  3. Long-running INSERT operations are not completing, holding threads hostage
  4. Database is configured with insufficient server resources (CPU, memory) to process queued inserts
  5. Multiple applications or processes are generating INSERT DELAYED requests simultaneously

How to fix "ERROR 1151: Too many delayed threads in use"

1Check your MySQL version first

Before adjusting configurations, verify whether your MySQL version still supports INSERT DELAYED. In MySQL 8.0+, the DELAYED keyword is deprecated and ignored—the server treats DELAYED inserts as regular inserts.

sql
SELECT VERSION();

If you are using MySQL 8.0 or later, consider refactoring your application to remove INSERT DELAYED entirely.

2View current delayed insert thread statistics

Connect to your MySQL instance and check the current number of active delayed insert threads and the configured limit:

sql
SHOW STATUS LIKE "Delayed_writes";
SHOW STATUS LIKE "Delayed_insert_threads";
SHOW VARIABLES LIKE "max_delayed_threads";

This shows you how many delayed threads are currently in use and the maximum allowed. If the current count is at or near the max_delayed_threads limit, you have found the bottleneck.

3Increase max_delayed_threads (temporary solution)

If you are still using a MySQL version that supports INSERT DELAYED (5.1 through 5.7), you can temporarily increase the max_delayed_threads limit. Add or modify the following in your MySQL configuration file (my.cnf or my.ini):

ini
[mysqld]
max_delayed_threads = 50

Then restart the MySQL service:

bash
sudo systemctl restart mysql
# or on some systems:
sudo service mysql restart

Monitor the impact with:

sql
SHOW STATUS LIKE "Delayed_insert_threads";

Note: Be cautious about setting this too high, as each thread consumes server memory and resources.

4Refactor application to use regular INSERT statements

The long-term solution is to eliminate INSERT DELAYED from your application code. Convert delayed insert calls to regular, non-delayed inserts:

Before (INSERT DELAYED):

sql
INSERT DELAYED INTO logs (user_id, action, timestamp)
VALUES (123, "login", NOW());

After (Regular INSERT):

sql
INSERT INTO logs (user_id, action, timestamp)
VALUES (123, "login", NOW());

If you need non-blocking inserts for performance, consider these alternatives:
- Use connection pooling to handle concurrent requests efficiently
- Implement a message queue (Redis, RabbitMQ) for async logging
- Batch multiple inserts into a single transaction
- Use prepared statements to reduce overhead

5Optimize delayed insert configuration parameters

For MySQL versions prior to 8.0, you can fine-tune related parameters to handle delayed inserts more efficiently:

ini
[mysqld]
delayed_insert_limit = 200      # Rows processed before checking for SELECT statements
delayed_insert_timeout = 600     # Seconds before idle thread terminates
delayed_queue_size = 2000        # Per-table queue size limit

These parameters help the server batch delayed operations more efficiently:
- Higher delayed_insert_limit allows more rows to be processed in one batch
- Higher delayed_insert_timeout keeps threads alive longer if traffic is intermittent
- Higher delayed_queue_size allows more rows to be queued per table

After making changes, restart MySQL and monitor performance.

6Monitor ongoing delayed insert activity

Set up monitoring to track delayed insert performance and ensure the error does not reoccur:

sql
-- Check delayed insert statistics
SHOW STATUS LIKE "Delayed%";

-- Monitor in real-time (run periodically)
WATCH -n 1 "mysql -e \"SHOW STATUS LIKE 'Delayed%';\"";

Key metrics to track:
- Delayed_writes: Total number of INSERT DELAYED statements executed
- Delayed_insert_threads: Current active delayed insert threads
- Delayed_errors: Failed delayed insert operations

If thread count approaches your configured limit again, you need further optimization or a migration strategy.

Advanced notes

INSERT DELAYED is a deprecated MySQL feature that was removed in version 8.0. If you encounter this error on MySQL 8.0+, your application is still attempting to use DELAYED inserts, but MySQL silently converts them to regular inserts and generates a deprecation warning (ER_WARN_LEGACY_SYNTAX_CONVERTED). For production systems, the best approach is to migrate away from DELAYED inserts entirely using async message queues or batch inserts. INSERT DELAYED only works with MyISAM, MEMORY, ARCHIVE, and BLACKHOLE table types—modern applications should use InnoDB instead. If you are on an older MySQL version (5.7 or earlier) and cannot immediately refactor, increasing max_delayed_threads provides temporary relief, but plan a migration to regular or asynchronous inserts as a long-term solution.

Frequently asked questions

What does "ERROR 1151: Too many delayed threads in use" mean?
MySQL Error 1151 (ER_TOO_MANY_DELAYED_THREADS) indicates that the database has reached its maximum limit for concurrent INSERT DELAYED handler threads. INSERT DELAYED is a MySQL feature that allows INSERT statements to be queued and executed in the background, improving application responsiveness during high-traffic scenarios. When too many delayed insert operations are queued simultaneously, MySQL refuses new delayed insert requests to prevent resource exhaustion.
How do I fix "ERROR 1151: Too many delayed threads in use"?
MySQL error 1151 occurs when the number of background INSERT DELAYED threads exceeds the configured limit. This legacy feature is deprecated in modern MySQL versions and typically requires adjusting max_delayed_threads or refactoring to use regular inserts.
What causes "ERROR 1151: Too many delayed threads in use"?
max_delayed_threads limit is too low for your application workload (default is 20) INSERT DELAYED statements are being generated faster than they can be processed Long-running INSERT operations are not completing, holding threads hostage
Is the "ERROR 1151: Too many delayed threads in use" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading