【MongoDB】查看数据库集合的占用空间,清理集合的冗存空间
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【MongoDB】查看数据库集合的占用空间,清理集合的冗存空间,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2180字,纯文字阅读大概需要4分钟。
内容图文
![【MongoDB】查看数据库集合的占用空间,清理集合的冗存空间](/upload/InfoBanner/zyjiaocheng/512/68e4b295b6114ac59d76bddee3a8fa26.jpg)
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上运行
不建议使用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】查看数据库集合的占用空间,清理集合的冗存空间
标签:careful long 建议 inter col fun ted man nod
本文系统来源:https://blog.51cto.com/l0vesql/2433344
内容总结
以上是互联网集市为您收集整理的【MongoDB】查看数据库集合的占用空间,清理集合的冗存空间全部内容,希望文章能够帮你解决【MongoDB】查看数据库集合的占用空间,清理集合的冗存空间所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。