Magento 2 uses a message queue system to handle asynchronous tasks like bulk operations, email sending, product reindexing, and more. However, sometimes, messages get stuck due to a crash, deadlock, or improper consumer handling — clogging the queue and slowing down the system.
In this quick guide, we’ll show you how to reset the Magento 2 queue system safely by truncating the right tables in the database.
Caution: This is a destructive operation. Make sure to take a full DB backup before performing these steps on production.
Why Do Queues Get Stuck?
Queues may get stuck due to:
- Consumers being stopped or crashed midway
- Invalid payloads or corrupted data in queue messages
- A long-pending bulk operation like product import or customer sync
- Database deadlocks or locks on queue-related tables
- Redis/MySQL failures during processing
Solution: Reset Stuck Queue in Magento 2
Here’s how you can truncate the queue-related tables to clear all stuck messages and restart fresh:
SQL Query to Reset Queues
-- Disable foreign key checks
SET FOREIGN_KEY_CHECKS=0;
-- Truncate all queue-related tables
TRUNCATE TABLE queue;
TRUNCATE TABLE queue_message;
TRUNCATE TABLE queue_message_status;
TRUNCATE TABLE magento_operation;
TRUNCATE TABLE magento_bulk;
-- Re-enable foreign key checks
SET FOREIGN_KEY_CHECKS=1;
📌 These tables are responsible for storing queue messages, their status, and bulk operation logs.
When to Use This?
You should truncate these tables when:
- Magento 2 Admin actions (bulk product update, reindex, etc.) are not completing
- You see messages stuck in
queue_message
ormagento_bulk
table withstatus = new
orstatus = running
for hours - The message queue consumer is running but not processing anything
- You’re resetting the staging/dev environment after a database copy from production
Restarting Consumers After Reset
Once the queue is truncated, restart the consumers to resume fresh processing:
php bin/magento queue:consumers:start
Or for specific consumers (example):
php bin/magento queue:consumers:start async.operations.all
Pro Tips
- Always take a database backup before truncating tables.
- You can check current stuck messages using:
SELECT * FROM queue_message WHERE status = 'new';
- Use
queue:consumers:list
to view available consumers.
Testing It Locally
In your local dev or staging, you can simulate a bulk import or reindex to see how the queue processes messages. If something fails, try the above reset to test how it behaves afterward.
Conclusion
Magento 2’s queue system is powerful but can occasionally hang due to background failures. By safely truncating queue-related tables and restarting consumers, you can unstick your Magento 2 instance without a full reset or reinstallation.
Have you encountered queue issues in production? Share your experience in the comments, or feel free to reach out for more advanced debugging techniques!
Leave a Comment