- Reference >
- Database Commands >
- Diagnostic Commands >
- dbStats
dbStats¶
On this page
Definition¶
-
dbStats¶ The
dbStatscommand returns storage statistics for a given database. The command takes the following syntax:scaleis optional and defaults to1.In the
mongoshell, thedb.stats()function provides a wrapper arounddbStats.
Behavior¶
The scale argument allows you to specify how to scale byte
values. For example, a scale value of 1024 will display the
results in kilobytes rather than in bytes:
Note
Scaling rounds values to whole numbers.
The time required to run the command depends on the total size of the database. Because the command must touch all data files, the command may take several seconds to run.
Accuracy after Unexpected Shutdown¶
After an unclean shutdown of a mongod using the Wired Tiger storage engine, count and size statistics reported by
dbStats may be inaccurate.
The amount of drift depends on the number of insert, update, or delete
operations performed between the last checkpoint and the unclean shutdown. Checkpoints
usually occur every 60 seconds. However, mongod instances running
with non-default --syncdelay settings may have more or less frequent
checkpoints.
Run validate on each collection on the mongod
to restore the correct statistics after an unclean shutdown.
Output¶
-
dbStats.db¶ Contains the name of the database.
-
dbStats.collections¶ Contains a count of the number of collections in that database.
-
dbStats.objects¶ Contains a count of the number of objects (i.e. documents) in the database across all collections.
-
dbStats.avgObjSize¶ The average size of each document in bytes. This is the
dataSizedivided by the number of documents. The scale argument does not affect theavgObjSizevalue.
-
dbStats.dataSize¶ The total size of the uncompressed data held in this database. The
dataSizedecreases when you remove documents.For databases using the MMAPv1 storage engine,
dataSizeincludes preallocated space and the padding factor. ThedataSizedoes not decrease when documents shrink.For databases using the WiredTiger storage engine,
dataSizemay be larger thanstorageSizeif compression is enabled. ThedataSizedecreases when documents shrink.
-
dbStats.storageSize¶ The total amount of space allocated to collections in this database for document storage. The
storageSizedoes not decrease as you remove or shrink documents. This value may be smaller thandataSizefor databases using the WiredTiger storage engine with compression enabled.
-
dbStats.numExtents¶ Contains a count of the number of extents in the database across all collections.
-
dbStats.indexes¶ Contains a count of the total number of indexes across all collections in the database.
-
dbStats.indexSize¶ The total size of all indexes created on this database.
-
dbStats.fileSize¶ The total size of the data files that hold the database. This value includes preallocated space and the padding factor. The value of
fileSizeonly reflects the size of the data files for the database and not the namespace file.Only present when using the
mmapv1storage engine.
-
dbStats.nsSizeMB¶ The total size of the namespace files (i.e. that end with
.ns) for this database. You cannot change the size of the namespace file after creating a database, but you can change the default size for all new namespace files with thensSizeruntime option.Only present when using the
mmapv1storage engine.See also
The
nsSizeoption, and Maximum Namespace File Size
-
dbStats.dataFileVersion¶ Document that contains information about the on-disk format of the data files for the database. Only present when using the
mmapv1storage engine.
-
dbStats.dataFileVersion.major¶ The major version number for the on-disk format of the data files for the database. Only present when using the
mmapv1storage engine.
-
dbStats.dataFileVersion.minor¶ The minor version number for the on-disk format of the data files for the database. Only present when using the
mmapv1storage engine.
-
dbStats.extentFreeList¶ New in version 3.0.0.
-
dbStats.extentFreeList.num¶ New in version 3.0.0.
Number of extents in the freelist. Only present when using the
mmapv1storage engine.
-
dbStats.extentFreeList.size¶ New in version 3.0.0.
Total size of the extents on the freelist.
Only present when using the
mmapv1storage engine.
-
dbStats.fsUsedSize¶ New in version 3.6.
Total size of all disk space in use on the filesystem where MongoDB stores data.
See also
-
dbStats.fsTotalSize¶ New in version 3.6.
Total size of all disk capacity on the filesystem where MongoDB stores data.