정의
dbStatsThe
dbStatscommand returns storage statistics for a given database.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
중요
This command has limited support in M0 and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
명령은 다음과 같은 구문을 가집니다:
db.runCommand( { dbStats: 1, scale: <number>, freeStorage: 0 } )
명령 필드
이 명령은 다음 필드를 사용합니다.
필드 | 설명 |
|---|---|
1 | |
선택 사항입니다. 다양한 크기의 데이터에 대한 배율 인수입니다. 크기 데이터를 바이트 단위로 반환하려면 정수가 아닌 배율 인수를 지정하면 MongoDB는 지정된 인수의 정수 부분을 사용합니다. 예를 들어, 배율 인수를 버전 4.2부터 출력에 크기 값의 크기를 조정하는 데 사용되는 | |
선택 사항입니다. 컬렉션에 할당된 여유 공간에 대한 정보를 반환하려면 If the instance has a large number of collections or indexes, obtaining free space usage data may cause processing delays. To gather |
mongosh에서 db.stats() 함수는 dbStats에 대한 래퍼(wrapper)를 제공합니다.
행동
명령을 실행하는 데 필요한 시간은 데이터베이스의 총 크기에 따라 달라집니다. 명령은 모든 데이터 파일을 처리해야 하므로 명령을 실행하는 데 몇 초 정도 걸릴 수 있습니다.
예기치 않은 종료 후 정확도
After an unclean shutdown of a mongod using the Wired Tiger storage engine, count and size statistics reported by dbStats may be inaccurate.
편차의 정도는 마지막 체크포인트와 비정상 종료 사이에 수행된 삽입, 업데이트 또는 삭제 작업의 수에 따라 달라집니다. 체크포인트는 보통 60초마다 발생합니다. 그러나mongod 기본값이 아닌 --syncdelay 설정으로 실행되는 인스턴스는 체크포인트가 다소 빈번하게 발생할 수 있습니다.
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.To include this value in the
dbStatsoutput, set freeStorage to 1.버전 5.3.0, 5.2.1, 및 5.0.6에서 업데이트됨
dbStats.indexSize사용 가능한 인덱스 공간을 포함하여 데이터베이스의 모든 인덱스에 할당된 디스크 공간의 합계입니다.
참고
필드 에 기본값 인덱스 만 있는 클러스터형
_ìd컬렉션( 세컨더리 인덱스 없음)에서는 컬렉션 에 별도의 인덱스 파일 필요하지 않기 때문에 인덱스 크기가 0으로 표시됩니다.
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에서 업데이트되었습니다,
예시
The following examples demonstrate dbStats usage.
반환되는 데이터 제한
반환되는 데이터를 단일 필드로 제한하려면 dbStats 명령에 필드 이름을 추가합니다. 이 예시에서는 indexSize 값을 반환합니다.
db.runCommand( { dbStats: 1 } ).indexSize
컬렉션에 할당된 여유 공간 보기
To view free storage usage, set freeStorage to 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 공간 필드를 사용하면 강조 표시된 메트릭을 수집하고 표시할 수 있습니다.
scale 필드는 표시되는 값을 킬로바이트로 설정합니다.