The WiredTiger storage engine maintains lists of empty records in data files as it deletes documents. This space can be reused by WiredTiger, but will not be returned to the operating system unless under very specific circumstances.
The amount of empty space available for reuse by WiredTiger is reflected in the output of
db.collection.stats()
under the headingwiredTiger.block-manager.file bytesavailable for reuse
.ref: https://docs.mongodb.com/v3.4/faq/storage/#how-do-i-reclaim-disk-space-in-wiredtigerTo allow the WiredTiger storage engine to release this empty space to the operating system, you can de-fragment your data file. This can be achieved using the
compact
command. For more information on its behavior and other considerations, seecompact
.
Hi Vihesh
I have already tried compact command on all collections, but no empty space got released.
Yes this may happen due to your workload and use case. From the compact page:
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. The effectiveness of this operation is workload dependent and no disk space may be recovered. This command is useful if you have removed a large amount of data from the collection, and do not plan to replace it.
If you plan to replace the documents, then reclaiming disk space is not strictly necessary, since WiredTiger will prefer to reuse space instead of growing the data files.
However, it is entirely possible that compact
doesn’t release a meaningful amount of space back to the OS. Having said that, you may try to rerun the compact
command again in the near future, and see if more space is released.
In a replica set environment, you can reclaim space by performing an initial sync, which involves emptying out the dbpath
to be reclaimed, then syncing the data from another node. This will create new data files that are only as big as necessary to contain all your data.
Best regards
Kevin