After 4.2, background createIndexes

From version 4.2 of mongodb, foreground and background index has been deleted.

Then is there no way to background indexing from the 4.2 version?

Hi @Kim_Hakseon,

Per the documentation page you linked, all index builds in MongoDB 4.2+ use an optimised build path and there is no longer an option for foreground or background builds. The background index build option will be ignored if specified.

The new index build process does not have the extensive blocking behaviour that was a concern for foreground index builds in previous server releases.

Index build performance in 4.2+ should be similar (or better) than before depending on whether the collection is being actively updated while the index is being built:

The optimized index build performance is at least on par with background index builds. For workloads with few or no updates received during the build process, optimized index builds can be as fast as a foreground index build on that same data.


1 Like

So in 4.2 version, is it impossible to do anything else in that collection while creating index is in progress like a background index?

Hi @Kim_Hakseon,

Unlike foreground index builds in prior server releases, 4.2+ index builds do not block database access while an index is being created.

There are further details in the two links you shared in your post, but the Behaviour section addresses this specifically (my performance quote above is from the same section):

Starting in MongoDB 4.2, index builds obtain an exclusive lock on only the collection being indexed during the start and end of the build process to protect metadata changes. The rest of the build process uses the yielding behavior of background index builds to maximize read-write access to the collection during the build. 4.2 index builds still produce efficient index data structures despite the more permissive locking behavior.

The new index build approach effectively delivers the previous benefits of background index builds with the potential efficiency and performance of foreground index builds depending on resource contention.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.