Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[MongoDB] View the occupied space of the database collection and clean up the redundancy of the collection

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Check the occupied space 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)}) under the library to clean up the redundant space / / primarydb.runCommand ({compact:'flow_down_stream_info',force:true}) / / secondarydb.runCommand ({compact:'flow_down_stream_info'})

It is recommended to run it on the slave library first, and then run it on primary after observing that there is no problem.

The repairDatabase () command is not recommended

It may cause data corruption.

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

In addition,

The repairDatabase command has no effect on GridFS's library

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report