AI Reports

Magento 2 troubleshooting › Indexing and cron

“One or more indexers are invalid” or “Reindex required”: how do I fix a stuck Magento indexer?

Short answer: The admin message One or more indexers are invalid. Make sure your Magento cron job is running. means an indexer needs a rebuild or cron isn't processing it. An indexer that crashed mid-run stays marked working, and Magento won't start it again. In Update by Schedule mode, changes also pile up in changelog tables when cron stops. Check both, then reset and reindex.

Each indexer has a status in indexer_state (valid, invalid, working). In Update by Schedule mode, triggers write changed IDs into *_cl changelog tables, and cron processes them; mview_state.version_id is how far it got.

Check it step by step

These queries only read data. Run them on a copy of your database if you can, or ask your developer to. If your tables have a prefix (set in app/etc/env.php), add it to each table name.

1. Indexer status

Works on Magento Open Source and Adobe Commerce:

SELECT indexer_id, status, updated
FROM indexer_state
ORDER BY status, indexer_id;

working with an old updated time means a run died. invalid means a full reindex is needed.

2. Schedule mode and how far each view got

Works on Magento Open Source and Adobe Commerce:

SELECT view_id, mode, status, version_id, updated
FROM mview_state
ORDER BY view_id;

A view stuck in working, or one whose updated time stopped moving, isn't being processed.

3. How many changes are waiting

The backlog is the newest changelog version minus the processed one. For the busiest indexers:

Works on Magento Open Source and Adobe Commerce:

SELECT 'catalog_product_price' AS view_id, (SELECT IFNULL(MAX(version_id), 0) FROM catalog_product_price_cl) - (SELECT version_id FROM mview_state WHERE view_id = 'catalog_product_price') AS backlog
UNION ALL SELECT 'catalogsearch_fulltext', (SELECT IFNULL(MAX(version_id), 0) FROM catalogsearch_fulltext_cl) - (SELECT version_id FROM mview_state WHERE view_id = 'catalogsearch_fulltext')
UNION ALL SELECT 'catalog_category_product', (SELECT IFNULL(MAX(version_id), 0) FROM catalog_category_product_cl) - (SELECT version_id FROM mview_state WHERE view_id = 'catalog_category_product')
UNION ALL SELECT 'catalog_product_category', (SELECT IFNULL(MAX(version_id), 0) FROM catalog_product_category_cl) - (SELECT version_id FROM mview_state WHERE view_id = 'catalog_product_category')
UNION ALL SELECT 'inventory', (SELECT IFNULL(MAX(version_id), 0) FROM inventory_cl) - (SELECT version_id FROM mview_state WHERE view_id = 'inventory')
UNION ALL SELECT 'catalogrule_product', (SELECT IFNULL(MAX(version_id), 0) FROM catalogrule_product_cl) - (SELECT version_id FROM mview_state WHERE view_id = 'catalogrule_product');

A few hundred is normal between cron runs. Tens of thousands that keep growing mean the indexer cron job isn't keeping up or isn't running.

How to fix it

Good to know

Related

Gaurav Harsh

Gaurav Harsh is a Magento developer who works on large Adobe Commerce stores and builds AI Reports, a Magento extension for asking your store's data questions in plain English. LinkedIn