【MongoDB】查看数据库集合的占用空间,清理集合的冗存空
发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,到库下面查看占用空间tables = db.getCollectionNames();tables.forEach( function (item) { stats=db.runCommand
千家信息网最后更新 2026年10月31日【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安全错误
数据库的锁怎样保障安全
瑰夏咖啡
互联网科技工作委员会主任
江苏根荣互联网科技
互联网科技上市公司
互联网科技网站
汉立互联网科技有限公司联系电话
创业天下互联网科技有限公司
顶级互联网科技成果有哪些
互联网科技项目计划书材料类
燊美集互联网科技有限公司
爱医互联网络科技
每天都有哪些好的互联网科技
信承诺互联网科技有限公司
互联网科技手机排行榜
版纳互联网科技选哪家
互联网公司属于科技吗
易租星互联网科技有限公司
广西泛欧互联网科技有限公司
恒生科技指数 中概互联网
北京品多多互联网科技有限公司
互联网科技会
互联网公司 科技公司
互联网科技公司发展
奇酷互联网科技公司
温州喔噻互联网科技有限公司
滨湖区互联网智能科技产品有哪些
新氧科技和美国互联网有关系吗
广州智享互联网科技
深圳互联网科技园地址
知域互联网科技有限公司官网