gpt4 book ai didi

mongodb - 为什么我的 mongodb fileSize 比 db.stats() 中的 storageSize 大得多?

转载 作者:IT老高 更新时间:2023-10-28 13:10:30 26 4
gpt4 key购买 nike

我有一个名为 log_test1 的数据库,只有 1 个上限收集日志。上限集合的最大大小为 512M。插入200k数据后,发现db的磁盘使用量为1.6G。使用 db.stats(),我可以看到 storageSize 是 512M,正确,但我实际的 fileSize 是 1.6G,为什么会这样?如何控制磁盘大小只是我的上限集合大小加上索引大小?

> use log_test1
switched to db log_test1
> db.stats()
{
"db" : "log_test1",
"collections" : 3,
"objects" : 200018,
"avgObjSize" : 615.8577328040476,
"dataSize" : 123182632,
"storageSize" : 512008192,
"numExtents" : 3,
"indexes" : 8,
"indexSize" : 71907920,
"fileSize" : 1610612736,
"nsSizeMB" : 16,
"dataFileVersion" : {
"major" : 4,
"minor" : 5
},
"ok" : 1
}

最佳答案

这可能是因为 MongoDB 预先分配了数据和日志文件。


MongoDB 2

In the data directory, MongoDB preallocates data files to a particular size, in part to prevent file system fragmentation. MongoDB names the first data file <databasename>.0, the next <databasename>.1, etc. The first file mongod allocates is 64 megabytes, the next 128 megabytes, and so on, up to 2 gigabytes, at which point all subsequent files are 2 gigabytes. The data files include files with allocated space but that hold no data. mongod may allocate a 1 gigabyte data file that may be 90% empty. For most larger databases, unused allocated space is small compared to the database.

On Unix-like systems, mongod preallocates an additional data file and initializes the disk space to 0. Preallocating data files in the background prevents significant delays when a new database file is next allocated.

You can disable preallocation with the noprealloc run time option. However noprealloc is not intended for use in production environments: only use noprealloc for testing and with small data sets where you frequently drop databases.

MongoDB 3

The data files in your data directory, which is the /data/db directory in default configurations, might be larger than the data set inserted into the database. Consider the following possible causes:

Preallocated data files

MongoDB preallocates its data files to avoid filesystem fragmentation, and because of this, the size of these files do not necessarily reflect the size of your data.

The storage.mmapv1.smallFiles option will reduce the size of these files, which may be useful if you have many small databases on disk.

The oplog

If this mongod is a member of a replica set, the data directory includes the oplog.rs file, which is a preallocated capped collection in the local database.

The default allocation is approximately 5% of disk space on 64-bit installations.

The journal

The data directory contains the journal files, which store write operations on disk before MongoDB applies them to databases.

Empty records

MongoDB maintains lists of empty records in data files as it deletes documents and collections. MongoDB can reuse this space, but will not, by default, return this space to the operating system.


取自 MongoDB Storage FAQ .

关于mongodb - 为什么我的 mongodb fileSize 比 db.stats() 中的 storageSize 大得多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20533419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com