Site icon Database Tutorials

Fragmentation on MongoDB databases

 

Fragmentation on MongoDB databases

When we removing a large amount of data from the collection and no plan to replace it, we generate a fragmentation, to deal with it, we have a COMPACT command.

The compact command rewrites and defragments all data and indexes in a collection, depending on what storage engine we have.

Differences between Storage – Engines (included in community edition)

COMMAND MMAPV1 WIREDTIGER
COMPACT On MMAPv1, compact defragments the collection’s data files and recreates its indexes. Unused disk space is not released to the system but instead retained for future data. On WiredTiger, compact attempts to reduce the required storage space for data and indexes in a collection, releasing unneeded disk space to the operating system.
COMPACT Compact requires up to 2 gigabytes of additional disk space to run on MMAPv1 databases. Compact does not require any additional disk space to run on WiredTiger databases
COMPACT  If you wish to reclaim disk space from an MMAPv1 database, you should perform an initial sync.

Considerations:

Compacting and Compressing are two different things, please don´t confuse. These two concepts are totally different in MongoDB.

Exit mobile version