【mongoDB】mongoDB查看可回收空间
2022-09-23 本文已影响0人
Bogon
在mongoDB中删除数据并不会直接释放磁盘,而是产生很多碎片。
这些碎片会被mongoDB继续利用。当有新数据插入时,会重复利用这些碎片,而不需要新申请磁盘空间。
这会导致的问题是,磁盘可能一直处于高水位的使用水平,对运维来说是一个定时炸弹。
因为碎片只会被所属的库使用,但我们经常会新建很多库,这就导致磁盘越来越紧张。
- 登录mongos
$ mongo --host xx.xx.xx.xx --port 20221 -u username -p 'XXX' --authenticationDatabase admin
2.查询库表统计数据
mongos> use testDB
mongos> show tables
fs.file
fs.chunks
> db.fs.chunks.stats()
mongos> db.fs.chunks.stats()
{
"sharded" : true,
"capped" : false,
"ns" : "testDB.fs.chunks",
"count" : 245910298,
"size" : NumberLong("32703228247613"),
"storageSize" : NumberLong("33153039863808"),
"totalIndexSize" : 8290955264,
"indexSizes" : {
"_id_" : 4113846272,
"files_id_1_n_1" : 4177108992
},
"avgObjSize" : 132988.2285793619,
"nindexes" : 2,
"nchunks" : 1541085,
"shards" : {
"fileShard01" : {
"ns" : "testDB.fs.chunks",
"size" : NumberLong("17401234406957"),
"count" : 138499373,
"avgObjSize" : 125641,
"storageSize" : NumberLong("17626939813888"),
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
"creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
"type" : "file",
"uri" : "statistics:table:testDB/collection-19--5608300396599085557",
"LSM" : {
"bloom filter false positives" : 0,
"bloom filter hits" : 0,
"bloom filter misses" : 0,
"bloom filter pages evicted from cache" : 0,
"bloom filter pages read into cache" : 0,
"bloom filters in the LSM tree" : 0,
"chunks in the LSM tree" : 0,
"highest merge generation in the LSM tree" : 0,
"queries that could have benefited from a Bloom filter that did not exist" : 0,
"sleep for LSM checkpoint throttle" : 0,
"sleep for LSM merge throttle" : 0,
"total size of bloom filters" : 0
},
"block-manager" : {
"allocations requiring file extension" : 98259298,
"blocks allocated" : 346996065,
"blocks freed" : 242980176,
"checkpoint size" : NumberLong("16309599211520"),
"file allocation unit size" : 4096,
"file bytes available for reuse" : NumberLong("1317318868992"),
"file magic number" : 120897,
"file major version number" : 1,
"file size in bytes" : NumberLong("17626939813888"),
"minor version number" : 0
},
"btree" : {
"btree checkpoint generation" : 1333238,
"column-store fixed-size leaf pages" : 0,
"column-store internal pages" : 0,
"column-store variable-size RLE encoded values" : 0,
"column-store variable-size deleted values" : 0,
"column-store variable-size leaf pages" : 0,
"fixed-record size" : 0,
"maximum internal page key size" : 368,
"maximum internal page size" : 4096,
"maximum leaf page key size" : 2867,
"maximum leaf page size" : 32768,
"maximum leaf page value size" : 67108864,
"maximum tree depth" : 6,
"number of key/value pairs" : 0,
"overflow pages" : 0,
"pages rewritten by compaction" : 0,
"row-store internal pages" : 0,
"row-store leaf pages" : 0
},
"cache" : {
"bytes currently in the cache" : 37246678209,
"bytes read into cache" : NumberLong("55583395055633"),
"bytes written from cache" : NumberLong("71526133443867"),
"checkpoint blocked page eviction" : 95808,
"data source pages selected for eviction unable to be evicted" : 5526297,
"hazard pointer blocked page eviction" : 77789,
"in-memory page passed criteria to be split" : 17120601,
"in-memory page splits" : 8546562,
"internal pages evicted" : 6602331,
"internal pages split during eviction" : 27399,
"leaf pages split during eviction" : 8510889,
"modified pages evicted" : 235877417,
"overflow pages read into cache" : 0,
"overflow values cached in memory" : 0,
"page split during eviction deepened the tree" : 3,
"page written requiring lookaside records" : 0,
"pages read into cache" : 247895381,
"pages read into cache requiring lookaside entries" : 0,
"pages requested from the cache" : 4866640699,
"pages written from cache" : 344677908,
"pages written requiring in-memory restoration" : 2356,
"tracked dirty bytes in the cache" : 4560204,
"unmodified pages evicted" : 43110287
},
"cache_walk" : {
"Average difference between current eviction generation when the page was last considered" : 0,
"Average on-disk page image size seen" : 0,
"Clean pages currently in cache" : 0,
"Current eviction generation" : 0,
"Dirty pages currently in cache" : 0,
"Entries in the root page" : 0,
"Internal pages currently in cache" : 0,
"Leaf pages currently in cache" : 0,
"Maximum difference between current eviction generation when the page was last considered" : 0,
"Maximum page size seen" : 0,
"Minimum on-disk page image size seen" : 0,
"On-disk page image sizes smaller than a single allocation unit" : 0,
"Pages created in memory and never written" : 0,
"Pages currently queued for eviction" : 0,
"Pages that could not be queued for eviction" : 0,
"Refs skipped during cache traversal" : 0,
"Size of the root page" : 0,
"Total number of pages currently in cache" : 0
},
"compression" : {
"compressed pages read" : 71960244,
"compressed pages written" : 90631158,
"page written failed to compress" : 236578843,
"page written was too small to compress" : 17466928,
"raw compression call failed, additional data available" : 0,
"raw compression call failed, no additional data available" : 0,
"raw compression call succeeded" : 0
},
"cursor" : {
"bulk-loaded cursor-insert calls" : 0,
"create calls" : 70490,
"cursor-insert key and value bytes inserted" : NumberLong("70960206436884"),
"cursor-remove key bytes removed" : 1182065549,
"cursor-update value bytes updated" : 0,
"insert calls" : 376052924,
"next calls" : 11,
"prev calls" : 1,
"remove calls" : 237423599,
"reset calls" : 1358424107,
"restarted searches" : 846962,
"search calls" : 956922247,
"search near calls" : 0,
"truncate calls" : 0,
"update calls" : 0
},
"reconciliation" : {
"dictionary matches" : 0,
"fast-path pages deleted" : 0,
"internal page key bytes discarded using suffix compression" : 362030838,
"internal page multi-block writes" : 3676934,
"internal-page overflow keys" : 0,
"leaf page key bytes discarded using prefix compression" : 0,
"leaf page multi-block writes" : 9742683,
"leaf-page overflow keys" : 0,
"maximum blocks required for a page" : 78,
"overflow values written" : 0,
"page checksum matches" : 127265990,
"page reconciliation calls" : 248147159,
"page reconciliation calls for eviction" : 11253541,
"pages deleted" : 222776642
},
"session" : {
"object compaction" : 0,
"open cursor count" : 768
},
"transaction" : {
"update conflicts" : 0
}
},
"nindexes" : 2,
"totalIndexSize" : 4593233920,
"indexSizes" : {
"files_id_1_n_1" : 2335735808,
"_id_" : 2257498112
},
"ok" : 1
},
"fileShard02" : {
"ns" : "testDB.fs.chunks",
"size" : NumberLong("15301993840656"),
"count" : 107410925,
"avgObjSize" : 142462,
"storageSize" : NumberLong("15526100049920"),
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
"creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
"type" : "file",
"uri" : "statistics:table:testDB/collection-34--1361242988508886758",
"LSM" : {
"bloom filter false positives" : 0,
"bloom filter hits" : 0,
"bloom filter misses" : 0,
"bloom filter pages evicted from cache" : 0,
"bloom filter pages read into cache" : 0,
"bloom filters in the LSM tree" : 0,
"chunks in the LSM tree" : 0,
"highest merge generation in the LSM tree" : 0,
"queries that could have benefited from a Bloom filter that did not exist" : 0,
"sleep for LSM checkpoint throttle" : 0,
"sleep for LSM merge throttle" : 0,
"total size of bloom filters" : 0
},
"block-manager" : {
"allocations requiring file extension" : 77917372,
"blocks allocated" : 304630049,
"blocks freed" : 220915732,
"checkpoint size" : NumberLong("14333067624448"),
"file allocation unit size" : 4096,
"file bytes available for reuse" : NumberLong("1193012965376"),
"file magic number" : 120897,
"file major version number" : 1,
"file size in bytes" : NumberLong("15526100049920"),
"minor version number" : 0
},
"btree" : {
"btree checkpoint generation" : 1317917,
"column-store fixed-size leaf pages" : 0,
"column-store internal pages" : 0,
"column-store variable-size RLE encoded values" : 0,
"column-store variable-size deleted values" : 0,
"column-store variable-size leaf pages" : 0,
"fixed-record size" : 0,
"maximum internal page key size" : 368,
"maximum internal page size" : 4096,
"maximum leaf page key size" : 2867,
"maximum leaf page size" : 32768,
"maximum leaf page value size" : 67108864,
"maximum tree depth" : 6,
"number of key/value pairs" : 0,
"overflow pages" : 0,
"pages rewritten by compaction" : 0,
"row-store internal pages" : 0,
"row-store leaf pages" : 0
},
"cache" : {
"bytes currently in the cache" : 22512509990,
"bytes read into cache" : NumberLong("50582796280803"),
"bytes written from cache" : NumberLong("64708842485864"),
"checkpoint blocked page eviction" : 106568,
"data source pages selected for eviction unable to be evicted" : 3183834,
"hazard pointer blocked page eviction" : 72067,
"in-memory page passed criteria to be split" : 15483422,
"in-memory page splits" : 7730511,
"internal pages evicted" : 6206437,
"internal pages split during eviction" : 25496,
"leaf pages split during eviction" : 7709116,
"modified pages evicted" : 215601873,
"overflow pages read into cache" : 0,
"overflow values cached in memory" : 0,
"page split during eviction deepened the tree" : 3,
"page written requiring lookaside records" : 0,
"pages read into cache" : 218970787,
"pages read into cache requiring lookaside entries" : 0,
"pages requested from the cache" : 4152875304,
"pages written from cache" : 302371116,
"pages written requiring in-memory restoration" : 2843,
"tracked dirty bytes in the cache" : 2137180,
"unmodified pages evicted" : 31270905
},
"cache_walk" : {
"Average difference between current eviction generation when the page was last considered" : 0,
"Average on-disk page image size seen" : 0,
"Clean pages currently in cache" : 0,
"Current eviction generation" : 0,
"Dirty pages currently in cache" : 0,
"Entries in the root page" : 0,
"Internal pages currently in cache" : 0,
"Leaf pages currently in cache" : 0,
"Maximum difference between current eviction generation when the page was last considered" : 0,
"Maximum page size seen" : 0,
"Minimum on-disk page image size seen" : 0,
"On-disk page image sizes smaller than a single allocation unit" : 0,
"Pages created in memory and never written" : 0,
"Pages currently queued for eviction" : 0,
"Pages that could not be queued for eviction" : 0,
"Refs skipped during cache traversal" : 0,
"Size of the root page" : 0,
"Total number of pages currently in cache" : 0
},
"compression" : {
"compressed pages read" : 60876156,
"compressed pages written" : 78182994,
"page written failed to compress" : 208240138,
"page written was too small to compress" : 15947473,
"raw compression call failed, additional data available" : 0,
"raw compression call failed, no additional data available" : 0,
"raw compression call succeeded" : 0
},
"cursor" : {
"bulk-loaded cursor-insert calls" : 0,
"create calls" : 460694,
"cursor-insert key and value bytes inserted" : NumberLong("64219755050251"),
"cursor-remove key bytes removed" : 1052253679,
"cursor-update value bytes updated" : 0,
"insert calls" : 319646151,
"next calls" : 10,
"prev calls" : 1,
"remove calls" : 212119803,
"reset calls" : 1150748604,
"restarted searches" : 735664,
"search calls" : 810955457,
"search near calls" : 0,
"truncate calls" : 0,
"update calls" : 0
},
"reconciliation" : {
"dictionary matches" : 0,
"fast-path pages deleted" : 0,
"internal page key bytes discarded using suffix compression" : 315741721,
"internal page multi-block writes" : 3431156,
"internal-page overflow keys" : 0,
"leaf page key bytes discarded using prefix compression" : 0,
"leaf page multi-block writes" : 8876367,
"leaf-page overflow keys" : 0,
"maximum blocks required for a page" : 63,
"overflow values written" : 0,
"page checksum matches" : 117204036,
"page reconciliation calls" : 227142046,
"page reconciliation calls for eviction" : 9647063,
"pages deleted" : 204078227
},
"session" : {
"object compaction" : 0,
"open cursor count" : 702
},
"transaction" : {
"update conflicts" : 0
}
},
"nindexes" : 2,
"totalIndexSize" : 3697721344,
"indexSizes" : {
"files_id_1_n_1" : 1841373184,
"_id_" : 1856348160
},
"ok" : 1
}
},
"ok" : 1
}
mongos> db.fs.chunks.stats().shards["fileShard01"].wiredTiger["block-manager"]["file bytes available for reuse"]
NumberLong("1317331156992")
mongos> db.fs.chunks.stats().shards["fileShard02"].wiredTiger["block-manager"]["file bytes available for reuse"]
NumberLong("1192716824576")
将Byte转换为G
$ echo "1317331156992" | awk '{sum+=$1} END{print sum/(1024^3)}'
1226.86
$ echo "1192716824576" | awk '{sum+=$1} END{print sum/(1024^3)}'
1110.8
- 查看预计可回收空间
3.1 单机或副本集,单位为字节
> db.getCollection('testColl').stats().wiredTiger["block-manager"]["file bytes available for reuse"]
3.2 分片模式(有多个shard,修改shard01为对应分片名),单位为字节
> db.getCollection('testColl').stats().shards["shard01"].wiredTiger["block-manager"]["file bytes available for reuse"]
参考
db.stats() 与 db.serverStats() 与 db.collection.stats()
https://blog.csdn.net/cml2016/article/details/100210981
mongoDB查看可回收空间
http://blog.chinaunix.net/uid-1757778-id-5858684.html
MongoDB磁盘清理那些事儿
https://www.lmlphp.com/user/57801/article/item/2509348/
https://xie.infoq.cn/article/d8cb871a7733646996f60641a