简体   繁体   English

MongoDB 占用太多空间?

[英]MongoDB taking too much space?

I have been using mongodb recently, and I have found out that it is taking a lot of space.我最近一直在使用 mongodb,我发现它占用了很多空间。

For example, in its db directory /var/lib/mongodb/, if I type "du -sh", then result turns out to be 417M.例如,在其 db 目录 /var/lib/mongodb/ 中,如果我键入“du -sh”,则结果是 417M。 The thing is that there are only few entries in database, and I do not know how that can take up to 400M of space.问题是数据库中只有很少的条目,我不知道这会占用 400M 的空间。 Is it normal?正常吗? or have I done something wrong?还是我做错了什么?

If space is an issue you can start up with a few options so the files aren't pre-allocated larger than your data.如果空间是一个问题,您可以从几个选项开始,这样文件就不会预先分配大于您的数据。 This will reduce performance, as then the data won't be contiguous on disk and will require allocation while you are insert/update data.这将降低性能,因为这样数据在磁盘上将不连续,并且在您插入/更新数据时需要分配。 Normally when data is deleted the space will not be released to the filesystem but the space in the allocated files will be reused by mongodb.通常当数据被删除时,空间不会释放到文件系统,但分配文件中的空间将被 mongodb 重用。

See this page for more information: http://www.mongodb.org/display/DOCS/Excessive+Disk+Space有关更多信息,请参阅此页面: http://www.mongodb.org/display/DOCS/Excessive+Disk+Space

Databases typically expand space automatically but do not return it when no longer needed.数据库通常会自动扩展空间,但在不再需要时不会返回它。 This can happen during tests or running queries.这可能在测试或运行查询期间发生。 Similarly if you have indexes or created aggregates with map-reduce they need to go somewhere next to "your" data.同样,如果您有索引或使用 map-reduce 创建的聚合,他们需要 go 在“您的”数据旁边的某个位置。

Special tools must be run manually to reclaim the space.必须手动运行特殊工具来回收空间。 Checkout the repair database functionality.检查修复数据库功能。

Run it and see how many is still used after cleaning.运行它,看看清洁后还有多少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM