【MongoDB】查看数据库集合的占用空间,清理集合的冗存空
发表于:2025-11-06 作者:千家信息网编辑
千家信息网最后更新 2025年11月06日,到库下面查看占用空间tables = db.getCollectionNames();tables.forEach( function (item) { stats=db.runCommand
千家信息网最后更新 2025年11月06日【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)})清理冗余空间
// primarydb.runCommand({compact:'flow_down_stream_info',force:true})// secondarydb.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 maintenanceMongoDB / WiredTiger: reduce storage size after deleting properties from documents
另外
repairDatabase命令对GridFS的库不起作用
空间
命令
建议
运行
数据
作用
冗余
问题
i.e.
观察
数据库
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
什么是服务器流量
金博士软件开发
服务器怎么接到另一台电脑上
dupp数据库
旅行偏好数据库
温州数据库管理员
5g制造商和网络安全
济南软件开发定制公司哪家强
物联网软件开发平台
QT 搭建rtmp服务器
小马激活工具服务器
操作数据库实验总结
荷兰发包服务器
顶航数据库
我的世界加入有mod的服务器
弗兹鲁克数据库
服务器安全检查的主要内容
成都市软件开发公司
体感游戏什么软件开发
临汾软件开发销售电话
服务器管理脚本怎么编写
3级网络技术考子网掩码吗
汇丰银行软件开发是干什么
三六零网络安全大会
360服务器安全防护在设置
中国青藤网络安全
五级及以上网络安全事件
电子商务网络技术书
山西省临汾市网络安全作业官网
网络安全是怎么样的