【MongoDB】查看数据库集合的占用空间,清理集合的冗存空

到库下面查看占用空间

tables = db.getCollectionNames();
tables.forEach( function (item) { 
    stats=db.runCommand({collStats:item});
    sizeGB = stats.storageSize/1024/1024/1024;
    prettyGB = Math.round(sizeGB)+ 'GB';
    print(item, prettyGB)
})

清理冗余空间

// primary
db.runCommand({compact:'flow_down_stream_info',force:true})
// secondary
db.runCommand({compact:'flow_down_stream_info'})

建议先在从库上运行,观察没问题后再在primary上运行

创新互联主要为客户提供服务项目涵盖了网页视觉设计、VI标志设计、营销推广、网站程序开发、HTML5响应式重庆网站建设手机网站制作设计、微商城、网站托管及网站维护、WEB系统开发、域名注册、国内外服务器租用、视频、平面设计、SEO优化排名。设计、前端、后端三个建站步骤的完善服务体系。一人跟踪测试的建站服务标准。已经为成都阳台护栏行业客户提供了网站开发服务。

不建议使用repairDatabase()命令

有可能造成数据损坏

Just to clarify, please be careful about using repairDatabase on a replica set node. repairDatabase is meant to be used to salvage readable data i.e. after a disk corruption, so it can remove unreadable data and let MongoDB start in the face of disk corruption.

If this node has an undetected disk corruption and you run repairDatabase on it, this could lead into that particular node having a different data content vs. the other node as a result of repairDatabase. Since MongoDB assumes all nodes in a replica set contains identical data, this could lead to crashes and hard to diagnose problems. Due to its nature, this issue could stay dormant for a long time, and suddenly manifest itself with a vengeance, seemingly without any apparent reason.

WiredTiger will eventually reuse the empty spaces with new data, and the periodic checkpointing that WiredTiger does could potentially release space to the OS without any intervention on your part.

If you really need to give space back to the OS, then an initial sync is the safest choice if you have a replica set. On a standalone, dump/restore will achieve the same result. Otherwise, compact is the safer choice vs. repairDatabase. Please backup your data before doing any of these, since in my opinion this would qualify as a major maintenance

MongoDB / WiredTiger: reduce storage size after deleting properties from documents

另外

repairDatabase命令对GridFS的库不起作用


网站标题:【MongoDB】查看数据库集合的占用空间,清理集合的冗存空
本文链接:http://bzwzjz.com/article/jjochh.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站建设 做网站设计 专业网站建设 营销网站建设 成都网站建设 企业手机网站建设 网站设计公司 定制网站建设 成都做网站建设公司 手机网站制作 手机网站制作 定制网站建设多少钱 营销网站建设 成都网站建设公司 成都网站设计 响应式网站设计 成都网站制作 成都网站制作 重庆手机网站建设 成都网站制作 H5网站制作 上市集团网站建设