Magento – “indexer_update_all_views” cron job runs seemingly forever

cronindexingmagento2

We are currently having the problem that the indexer_update_all_views cron job seemingly runs forever – even though there aren't that many entries in the backlog of the indexer.

Last time we let the cron process run for almost 24 hours before killing it manually. For comparison: doing a complete manual indexer:reset and indexer:reindex only takes about 60 to 90 minutes.

Could it be that the indexer_update_all_views somehow gets stuck or deadlocked? There aren't any errors in the logs – and the process simply "never" finishes (which it would if there was an error).

Any ideas?

Magento version: 2.3.2

Best Answer

I was able to - at least temporarily - fix the problem by doing a complete, manual reset of the indexing process.

First disable the cronjob. Make sure no job will be running anymore (ps aux | grep bin/magento).

Then execute the following SQL statements:

// reset the cron_schedule table, in case you killed processes manually
TRUNCATE TABLE `cron_schedule`;

// reset all the indexing trigger tables
TRUNCATE TABLE `catalog_category_flat_cl`;
TRUNCATE TABLE `catalog_category_product_cl`;
TRUNCATE TABLE `catalog_product_attribute_cl`;
TRUNCATE TABLE `catalog_product_category_cl`;
TRUNCATE TABLE `catalog_product_flat_cl`;
TRUNCATE TABLE `catalog_product_price_cl`;
TRUNCATE TABLE `cataloginventory_stock_cl`;
TRUNCATE TABLE `catalogrule_product_cl`;
TRUNCATE TABLE `catalogrule_rule_cl`;
TRUNCATE TABLE `catalogsearch_fulltext_cl`;
TRUNCATE TABLE `customer_dummy_cl`;
TRUNCATE TABLE `design_config_dummy_cl`;

// reset the mview and indexer state tables
UPDATE `mview_state` SET `version_id` = '0', `status` = 'idle';
UPDATE `indexer_state` SET `status` = 'invalid';

Then do a complete re-index:

bin/magento indexer:reset && bin/magento indexer:reindex

After the re-indexing is finished, enable the cron again.

See also https://magento.stackexchange.com/a/164321/37461