定義
dbStatsThe
dbStatscommand returns storage statistics for a given database.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
重要
このコマンドは、M0 およびフレックス クラスターで限定的にサポートされています。詳細については、「サポートされていないコマンド」を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
このコマンドの構文は、次のとおりです。
db.runCommand( { dbStats: 1, scale: <number>, freeStorage: 0 } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | 説明 |
|---|---|
1 | |
任意。 さまざまなサイズ データの増やす ファクター。 整数以外のスケール係数を指定した場合、MongoDB は指定された係数の整数部分を使用します。たとえば、スケール係数を バージョン 4.2 以降では、出力にサイズ値を増やすのに使用される | |
任意。コレクションに割り当てられた空き領域の詳細を返すには、 インスタンスに多数のコレクションまたはインデックスがある場合、空き領域の使用状況データを取得すると、処理が遅れる可能性があります。空き領域の詳細なしで |
In mongosh, the db.stats() function provides a wrapper around dbStats.
動作
コマンドの実行に必要な時間は、データベースの合計サイズによって異なります。コマンドはすべてのデータファイルにアクセスする必要があるため、コマンドの実行には数秒かかる場合があります。
予期しないシャットダウン後の精度
After an unclean shutdown of a mongod using the Wired Tiger storage engine, count and size statistics reported by dbStats may be inaccurate.
ドリフトの量は、チェックポイントからクリーン シャットダウンまでの間に実行された挿入、アップデート、または削除操作の数によって異なります。チェックポイントは通常、60 秒ごとに発現します。ただし、デフォルト以外の --syncdelay 設定で実行されている mongod インスタンスでは、チェックポイントの頻度が増減する可能性があります。
不正なシャットダウン後に統計を復元するには、mongod の各コレクションに対して validate を実行します。
不正なシャットダウン後:
レプリカセット ノードの状態の制限
To run on a replica set member, dbStats operations require the member to be in PRIMARY or SECONDARY state. If the member is in another state, such as STARTUP2, the operation errors.
出力
dbStats.viewsデータベース内のビュー数。
dbStats.objectsすべてのコレクションにわたるデータベース内のオブジェクト(具体的には、ドキュメント)の数。
dbStats.avgObjSizeAverage size of each document in bytes. This is the
dataSizedivided by the number of documents. The scale argument does not affect theavgObjSizevalue.
dbStats.dataSizeTotal size of the uncompressed data held in the database. The
dataSizedecreases when you remove documents.WiredTiger ストレージ エンジンを使用するデータベースの場合、圧縮が有効になっていると、
dataSizeがstorageSizeより大きくなる可能性があります。ドキュメントが縮小すると、dataSizeは減少します。
dbStats.storageSizeドキュメントストレージ用にデータベース内のすべてのコレクションに割り当てられたディスク領域の合計(空き領域を含む)。
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.storageSizedoes not include space allocated to indexes. SeeindexSizefor the total index size.
dbStats.freeStorageSizeドキュメントストレージ用にデータベース内のすべてのコレクションに割り当てられた空き領域の合計。データベース・ストレージの空き領域はコレクションに割り当てられていますが、データは含まれていません。
freeStorageSizedoes not include free space allocated to indexes. SeeindexFreeStorageSizefor the total free index size.この値を
dbStatsの出力に含めるには、 freeStorage を1 に設定します。バージョン 5.3.0、5.2.1、および 5.0.6 でアップデート
dbStats.indexFreeStorageSizeデータベース内のすべてのインデックスに割り当てられたディスクの空き領域の合計。データベース・ストレージの空き領域はインデックスに割り当てられていますが、データは含まれていません。
indexFreeStorageSizedoes not include free space allocated to document storage. SeefreeStorageSizefor the total free document storage size.indexFreeStorageSize進行中のインデックス構築は含まれません。To include this value in the
dbStatsoutput, set freeStorage to 1.バージョン 7.0、6.3.2、6.0.7、5.3.0、5.2.1、5.0.19、5.0.6 でアップデート
dbStats.totalSizeSum of the disk space allocated for both documents and indexes in all collections in the database. Includes used and free storage space. This is the sum of
storageSizeandindexSize.
dbStats.totalFreeStorageSizeSum of the free storage space allocated for both documents and indexes in all collections in the database. This is the sum of
freeStorageSizeandindexFreeStorageSize.To include this value in the
dbStatsoutput, set freeStorage to 1.バージョン 5.3.0、5.2.1、および 5.0.6 でアップデート。
dbStats.scaleFactorscale値(コマンドで使用)。整数以外のスケール係数を指定した場合、MongoDB は指定された係数の整数部分を使用します。たとえば、スケール係数を
1023.999に指定すると、MongoDB はスケール係数として1023使用します。
例
The following examples demonstrate dbStats usage.
返されるデータの制限
To limit the data returned to a single field, append the field name to the dbStats command. This example returns the indexSize value:
db.runCommand( { dbStats: 1 } ).indexSize
コレクションに割り当てられた空き領域を表示する
ストレージのストレージの使用状況を表示するには、 freeStorage を1 に設定します。
db.runCommand( { dbStats: 1, scale: 1024, freeStorage: 1 } )
出力例:
{ db: 'test', collections: 2, views: 0, objects: 1689, avgObjSize: 52.56542332741267, dataSize: 86.7021484375, storageSize: 100, freeStorageSize: 32, indexes: 2, indexSize: 116, indexFreeStorageSize: 36, totalSize: 216, totalFreeStorageSize: 68, scaleFactor: 1024, fsUsedSize: 60155820, fsTotalSize: 61255492, ok: 1, '$clusterTime': { clusterTime: Timestamp({ t: 1646085664, i: 1 }), signature: { hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0), keyId: Long("0") } }, operationTime: Timestamp({ t: 1646085664, i: 1 }) }
freeStorageフィールドを使用すると、強調表示されたメトリクスの収集と表示が可能になります。
スケールフィールドでは、表示される値をキロバイトに設定します。