How to reclaim disk space in MongoDB

1,321 views
Skip to first unread message

Vishesh Singhal

unread,
Feb 15, 2018, 3:31:59 AM2/15/18
to mongodb-user
Hi,

We are using MongoDB v3.4.4 standalone server, which is taking around 30GB of disk space, now I have deleted half of the data from each collection but still it is taking 30GB of space.
How could I reclaim that free disk space ?


Regards,
Vishesh

iain wright

unread,
Feb 15, 2018, 1:34:27 PM2/15/18
to mongodb-user
Assuming you're using WT:

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 heading wiredTiger.block-manager.file bytesavailable for reuse.

To 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, see compact.

ref: https://docs.mongodb.com/v3.4/faq/storage/#how-do-i-reclaim-disk-space-in-wiredtiger

Vishesh Singhal

unread,
Feb 15, 2018, 11:27:02 PM2/15/18
to mongodb-user
Yes I am using WT.
    
          I have already tried compact command on all collections, but no empty space got released.


Regards,
Vishesh

Kevin Adistambha

unread,
Feb 27, 2018, 11:29:45 PM2/27/18
to mongodb-user

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

Reply all
Reply to author
Forward
0 new messages