The admin panel timed out when trying to open the orders list. 30-second timeout. The database contained 500,000 orders accumulated over 5 years. Fix time: 3 hours.
Symptoms
- Opening Sales > Orders ends in browser timeout
- MySQL slow log: COUNT query on
sales_ordertable takes 28 seconds - Problem grew gradually over recent months
Solution
bin/magento sales:archive --active # Enable order archiving in configuration # Stores > Configuration > Sales > Sales > Orders Archiving # Enable Archiving: Yes # Archive Orders Purchased: 90 days ago and earlier
ALTER TABLE sales_order
ADD INDEX idx_created_status (created_at, status),
ADD INDEX idx_customer_email (customer_email);
ALTER TABLE sales_order_grid
ADD INDEX idx_created_at (created_at);
OPTIMIZE TABLE sales_order_grid;
bin/magento sales:quote:cleanup # Result: orders grid loads in 0.8s instead of timeout
Takeaways
Shops running for several years accumulate hundreds of thousands of records. Order archiving and regular OPTIMIZE TABLE are fundamental to maintaining performance. Plan archiving before you reach the critical point.
