Site icon MageComp Blog

How to Unlock Reindex Process in Magento 2

How to Unlock Reindex Process in Magento 2

Hello Magento Friends,

Welcome to Magento Tutorial Series in which I will illustrate all about How to Unlock Reindex Process in Magento 2. Let’s get in

Introduction:

Many times when there is an indexing process going on during that time there is a common issue faced by everyone which is in an error message like “index is locked by another reindex process. Skipping.” This is because of fatal error, timeout, limited memory, or disruption through other processes.

When the index type is locked then you will not be able to reindex that specific locked index type. When you try to reindex that then it will always be skipped. To overcome this situation follow the solution given below with the appropriate code.

Steps to Unlock Reindex Process in Magento 2:

Step 1: Reindex when Index is Locked

Run the below command for reindexing:

php bin/magento indexer:reindex

You will find the stock process is been skipped as shown below

Design Config Grid index has been rebuilt successfully in 00:00:04
Customer Grid index has been rebuilt successfully in 00:00:06
Category Products index has been rebuilt successfully in 00:00:02
Product Categories index has been rebuilt successfully in 00:00:00
Product Price index has been rebuilt successfully in 00:00:01
Product EAV index has been rebuilt successfully in 00:00:00
Catalog Search index has been rebuilt successfully in 00:00:04
Stock index is locked by another reindex process. Skipping.
Catalog Rule Product index has been rebuilt successfully in 00:00:00
Catalog Product Rule index has been rebuilt successfully in 00:00:00

Step 2: Get Index Types Info

Firstly you have to view the list of index types of your Magento 2 and for that run the given below command:

php bin/magento indexer:info

After running the command, you will get the output given below:

design_config_grid Design Config Grid
customer_grid Customer Grid
catalog_category_product Category Products
catalog_product_category Product Categories
catalog_product_price Product Price
catalog_product_attribute Product EAV
catalogsearch_fulltext Catalog Search
cataloginventory_stock Stock
catalogrule_rule Catalog Rule Product
catalogrule_product Catalog Product Rule

Step 3: Check Index Types Status

Now check the status of all the index types by running the command given below:

php bin/magento indexer:status

After running the command, you will get the output given below:

+---------------------------+----------------------+--------+-----------+-----------------+------------------+
| ID                        | Title                | Status | Update On | Schedule Status | Schedule Updated |
+---------------------------+----------------------+--------+-----------+-----------------+------------------+
| catalogrule_product       | Catalog Product Rule | Ready  | Save      |                 |                  |
| catalogrule_rule          | Catalog Rule Product | Ready  | Save      |                 |                  |
| catalogsearch_fulltext    | Catalog Search       | Ready  | Save      |                 |                  |
| catalog_category_product  | Category Products    | Ready  | Save      |                 |                  |
| customer_grid             | Customer Grid        | Ready  | Save      |                 |                  |
| design_config_grid        | Design Config Grid   | Ready  | Save      |                 |                  |
| inventory                 | Inventory            | Ready  | Save      |                 |                  |
| catalog_product_category  | Product Categories   | Ready  | Save      |                 |                  |
| catalog_product_attribute | Product EAV          | Ready  | Save      |                 |                  |
| catalog_product_price     | Product Price        | Ready  | Save      |                 |                  |
| cataloginventory_stock    | Stock                |Processing| Save    |                 |                  |
+---------------------------+----------------------+--------+-----------+-----------------+------------------+

Step 4: Reset Index Types

For solving this issue you have to reset the index types which are locked run below given command:

php bin/magento indexer:reset

To reset multiple index types run the command given below:

php bin/magento indexer:reset IndexType1 IndexType2 IndexType3

Here only one index type is locked so we will run the given below command:

php bin/magento indexer:reset cataloginventory_stock

Output after running the above command will be like:

Stock indexer has been invalidated.

Step 5:  Reindex Index Types 

You have to check once again the indexer status so run the following command again:

php bin/magento indexer:status

The output after running the above command will be:

+---------------------------+----------------------+------------------+-----------+-----------------+------------------+
| ID                        | Title                | Status           | Update On | Schedule Status | Schedule Updated |
+---------------------------+----------------------+------------------+-----------+-----------------+------------------+
| catalogrule_product       | Catalog Product Rule | Ready            | Save      |                 |                  |
| catalogrule_rule          | Catalog Rule Product | Ready            | Save      |                 |                  |
| catalogsearch_fulltext    | Catalog Search       | Ready            | Save      |                 |                  |
| catalog_category_product  | Category Products    | Ready            | Save      |                 |                  |
| customer_grid             | Customer Grid        | Ready            | Save      |                 |                  |
| design_config_grid        | Design Config Grid   | Ready            | Save      |                 |                  |
| inventory                 | Inventory            | Ready            | Save      |                 |                  |
| catalog_product_category  | Product Categories   | Ready            | Save      |                 |                  |
| catalog_product_attribute | Product EAV          | Ready            | Save      |                 |                  |
| catalog_product_price     | Product Price        | Ready            | Save      |                 |                  |
| cataloginventory_stock    | Stock                | Reindex required | Save      |                 |                  |
+---------------------------+----------------------+------------------+-----------+-----------------+------------------+

You will be able to view the stock index type and it has been successfully unlocked.

Step 6: Final Reindex after Unlocking

Lastly reindex the Stock index type by running the given below command:

php bin/magento indexer:reindex cataloginventory_stock

The final output will be like:

Stock index has been rebuilt successfully in 00:00:01
Catalog Search index has been rebuilt successfully in 00:00:07

By following the above given easy steps you will be successfully able to unlock the reindex process going on which is very necessary for your Magento 2.

Final Words:

I hope the above explanation on How to Unlock the Reindex Process in Magento 2 will be helpful to you. You can also Perform Reindexing Programmatically in Magento 2.

And if you feel any queries related to it then you can contact our Support Team for any guidance. Don’t hesitate to comment on your reviews related to this article and also share the article with your Magento buddies for making them more knowledgeable.

Happy Reading!

Exit mobile version