Insights

    Magento 2 Reindex and Indexers: Modes, Commands and Fixes

    By Simon Bumford, Founder of EveryHostLast updated 7 min read

    To reindex Magento 2, run bin/magento indexer:reindex from the Magento root as the user that owns the Magento files. For day-to-day running, put the indexers on Update by Schedule and make sure cron is running, so Magento keeps its indexes up to date in the background. If an index is stuck or locked, reset it with bin/magento indexer:reset and reindex it. This guide explains what each indexer does, the two modes, every indexer command, and how to fix the common problems.

    What Magento indexers do

    Indexers turn Magento's detailed catalogue data into ready-made tables, so pages can be built without heavy database work on every visit.

    Magento stores products, prices, categories and stock in many related tables. Building a category page straight from those would be slow, so each indexer pre-calculates one view of the data. These are the core indexers in Magento Open Source:

    CodeNameWhat it indexes
    design_config_gridDesign Config GridThe admin's design configuration grid
    customer_gridCustomer GridThe admin's customer grid
    catalog_category_productCategory ProductsWhich products belong to which categories
    catalog_product_categoryProduct CategoriesThe same links, from the product side
    catalogrule_ruleCatalog Rule ProductCatalog price rules applied to products
    catalogrule_productCatalog Product RuleThe same rules, from the product side
    catalog_product_attributeProduct EAVProduct attribute values in a flat structure for faster lookups
    cataloginventory_stockStockStock status
    inventoryInventoryInventory Management stock
    catalog_product_priceProduct PricePre-calculated product prices
    catalogsearch_fulltextCatalog SearchThe search index, held in OpenSearch

    Adobe Commerce adds its own, for example for related-product rules. Extensions can add more. To see the exact list on your store:

    bin/magento indexer:info

    Update on Save vs Update by Schedule

    Update on Save reindexes the moment data changes; Update by Schedule records the change and lets cron reindex it in the background.

    On Update on Save (realtime), every product save, price change or stock update reindexes straight away, inside the request that made the change. On a busy store or a big import, that makes admin saves slow and puts load on the database at the wrong time.

    On Update by Schedule (schedule), Magento adds database triggers that write the IDs of changed records into changelog tables ending in _cl. The indexer_update_all_views cron job then reindexes just those records. Two other cron jobs help: indexer_reindex_all_invalid rebuilds any index marked invalid, and indexer_clean_all_changelogs clears old changelog rows.

    Adobe advises: "Set the indexers to Update on Schedule for large sites, and sites with frequent updates and heavy traffic." Since Magento 2.4.8, Update by Schedule is the default. One version catch: before 2.4.8, the Customer Grid indexer only supports Update on Save. From 2.4.8 it supports both modes.

    Update by Schedule only works if cron is running. If cron stops, changes stop reaching the store front. See Magento 2 cron not running?

    Magento reindex commands

    Run these from the Magento root as the file system owner. Leaving out the indexer name applies a command to all indexers.

    bin/magento indexer:info
    bin/magento indexer:status
    bin/magento indexer:show-mode
    bin/magento indexer:set-mode schedule
    bin/magento indexer:reindex
    bin/magento indexer:reindex catalog_product_price
    bin/magento indexer:reset catalogsearch_fulltext
    CommandWhat it does
    indexer:infoLists every indexer's code and name
    indexer:status [indexer]Shows whether each index is valid, needs reindexing or is processing
    indexer:show-mode [indexer]Shows Update on Save or Update by Schedule
    indexer:set-mode <mode> [indexer]Switches the mode: realtime (Update on Save) or schedule (Update by Schedule)
    indexer:reindex [indexer]Rebuilds the index in full
    indexer:reset [indexer]Marks the index invalid, so it will be rebuilt
    indexer:set-status <status> [indexer]Sets the status directly to invalid, suspended or valid; Magento 2.4.7 and later
    indexer:show-dimensions-mode and indexer:set-dimensions-modeSplit the price index by website or customer group, on large catalogues

    Adobe recommends putting the store into maintenance mode and pausing cron before you change indexer modes, so plan mode changes for a quiet time and try them on staging first.

    Asynchronous indexing in Magento 2

    "Asynchronous indexing" usually means one of two things: Update by Schedule, above, or asynchronous indexing of the admin's sales grids.

    With asynchronous grid indexing on, placing an order no longer waits for the order, invoice, shipment and credit memo grids to update; cron updates them shortly afterwards. Adobe recommends it to prevent database locks and slowed processing. The setting lives in the admin's Developer section, which is hidden in production mode, so set it from the command line:

    bin/magento config:set dev/grid/async_indexing 1

    Cron must be running for the grids to update.

    Why Magento indexers get stuck

    "Reindex required"

    When an index shows as needing a reindex and doesn't recover, Adobe's explanation is that "A change has been made that requires reindexing, but the indexers cannot be updated automatically. Check to see if cron is available and configured correctly." Check cron first, then run bin/magento indexer:reindex if you need the index rebuilt straight away.

    "Index is locked by another reindex process"

    If a reindex fails with "Index is locked by another reindex process. Skipping.", an earlier run didn't finish, often because of PHP's memory limit, a database timeout or a fatal PHP error. Adobe's fix is to reset that index and reindex it:

    bin/magento indexer:reset <indexer>
    bin/magento indexer:reindex <indexer>

    Then find out why the earlier run died. From Magento 2.4.3, Adobe also describes an indexer setting, use_application_lock, in app/etc/env.php to manage indexer locks more reliably.

    Changes not reaching the store front

    If an indexer is on Update by Schedule but changes never appear, check that the indexer_update_all_views cron job is succeeding. If the database triggers have gone missing, for example after a database copy, Adobe's advice is to switch the indexer to Update on Save and back to Update by Schedule, which recreates them.

    Speeding up a full reindex

    A full reindex of a large catalogue can take a long time. Adobe documents two options for developers: tuning the batch sizes each indexer uses, set with batchRowsCount in a module's etc/di.xml, and running some indexers in parallel with the MAGE_INDEXER_THREADS_COUNT environment variable, which needs PHP's pcntl extension. Both are worth testing on staging with your own catalogue before using them in production.

    How OpenSearch fits

    The Catalog Search indexer writes its data to the search engine, OpenSearch on current Magento releases, which Magento 2.4 requires for catalogue search. If OpenSearch is down or short of memory, the search reindex fails and search results go stale. More on running it well in Redis and OpenSearch for Magento.

    Symptom, cause and fix

    SymptomLikely causeWhere to checkFix
    Admin saves are slowIndexers on Update on Savebin/magento indexer:show-modebin/magento indexer:set-mode schedule, on staging first
    Prices, stock or new products not updatingCron not running, or the view update job failingcron_schedule, indexer_update_all_viewsFix cron
    "Reindex required" that never clearsCron not runningbin/magento indexer:status, crontabFix cron, then bin/magento indexer:reindex
    "Index is locked by another reindex process"An earlier reindex diedPHP and database logsbin/magento indexer:reset, then indexer:reindex
    Search results out of dateCatalog Search index or OpenSearch unhealthybin/magento indexer:status, OpenSearch healthFix OpenSearch, then reindex catalogsearch_fulltext
    Orders slow to place, sales grids laggingSynchronous grid indexingdev/grid/async_indexingbin/magento config:set dev/grid/async_indexing 1
    Scheduled changes never apply after a database copyMissing triggersbin/magento indexer:show-modeSwitch to Update on Save and back to Update by Schedule

    Indexers on EveryHost servers

    On EveryHost servers, cron is set up as part of the server, so Update by Schedule works from the start. Our Managed and Fully Managed plans watch indexers, message queues and the Magento cron heartbeat, and an engineer investigates every alert. Managed includes up to 30 minutes a month of small server tasks, such as cache and index operations, and Fully Managed up to 60 minutes. For a wider look at why a store is slow, see Why is Magento slow?

    Frequently asked questions

    Run bin/magento indexer:reindex from the Magento root as the user that owns the Magento files. Add an indexer code, such as catalog_product_price, to rebuild just one. For normal running, put the indexers on Update by Schedule and keep cron running, so you rarely need a full reindex.

    Update on Save reindexes as soon as data changes, inside the save itself, which slows the admin and loads the database. Update by Schedule records what changed and lets cron reindex it in the background. Adobe recommends Update by Schedule for large and busy stores, and it has been the default since Magento 2.4.8.

    It means data has changed and the index hasn't been rebuilt automatically. Adobe's advice is to check that cron is available and configured correctly, because the indexers depend on it. Once cron is fixed, run bin/magento indexer:reindex if you need the index rebuilt straight away.

    An earlier reindex didn't finish, often because it ran out of memory or hit a database timeout. Reset the index with bin/magento indexer:reset followed by the indexer code, then run bin/magento indexer:reindex for it, and find out why the earlier run died.

    It usually means asynchronous indexing of the admin's sales grids: orders, invoices, shipments and credit memos are added to their grids by cron shortly after, instead of during the order. Turn it on with bin/magento config:set dev/grid/async_indexing 1. It can also refer to indexers on Update by Schedule.

    Want your indexers watched for you?

    Our Managed and Fully Managed plans monitor indexers, message queues and cron on the stores we host.