user626206
user626206

Reputation: 687

What is meant by filesize and datasize in MongoDB?

I am started using MongoDB few days ago, and i have problem in understanding some database architecture. If i execute the query db.stats(); i had got filesize ,datasize,storagesize & indexsize. While i am surfing i found that the following:

Storagesize = datasize + free space allocated for collection

datasize = database size utilised by MongoDB

Here, I could not understand the representaion of filesize & datasize reprsentation. For datasize --> indexsize is also included?. Please provide a precise solution for the specified attributes and please do correct me if i mentioned anythng wrong.

Advance Thanks,

Upvotes: 8

Views: 5165

Answers (3)

J.M.
J.M.

Reputation: 721

As explained in this post about the different MongoDB performance metrics you should monitor (with MMAPv1), here are all the storage size metrics returned by dbStats that you should track:

  • dataSize measures the space taken by all the documents and padding in the database. Because of padding, dataSize decreases if documents are deleted but not when they shrink or get bigger following an update—those operations just add to or borrow from the document’s padding.
  • indexSize returns the size of all indexes created on the database.
  • storageSize measures the size of all the data extents in the database. With MMAPv1, it’s always greater than or equal to dataSize because extents contain free space not yet used or freed by deleted and moved documents. storageSize is not affected when documents shrink or are moved.
  • fileSize corresponds to the size of your data files. It’s obviously always larger than storageSize and can be seen as the storage footprint of you database on disk. It decreases only if you delete a database and is not affected when collections, documents, or indexes are removed.

Here is a diagram with the different important storage metrics returned by dbStats: dbStats storage metrics for MongoDB NOTE: With the MMAPv1 storage engine, MongoDB pre-allocates extra space on the disk to documents so efficient in-place updates are possible since documents have room to grow without having to be relocated. This extra space is called padding.

Upvotes: 2

dontGoPlastic
dontGoPlastic

Reputation: 1782

I realize this is an older question, but I figured I'd link to the official docs for db.stats() for anyone else looking for similar info (as I was).

Database Statistics Reference :: Fields

Upvotes: 1

Remon van Vliet
Remon van Vliet

Reputation: 18595

  • dataSize : Sum of all actual data (BSON objects) used by the database, in bytes
  • indexSize : Sum of all indexes used by the database, in bytes
  • storageSize : dataSize plus all preallocated collection space, in bytes
  • fileSize : Sum of the sizes of all files allocated for this database (e.g. test.0 + test.1 etc.), in bytes
  • nsSizeMB : Size of namespace file for this database, in megabytes.
  • avgObjSize : Average size of document objects in database. This value includes padding and may therefore not change when you reduce the size of documents.

Upvotes: 18

Related Questions