使用MongoDB如何改善数据空洞
PHPz
PHPz 2017-04-22 08:56:10
0
1
821

数据空洞指的是,一个表经历了频繁的update和delete后,其数据文件的尺寸大于其数据实际尺寸。比如show dbs看到一个库为400G,导出再导入后就只有250G。

PHPz
PHPz

学习是最好的投资!

reply all(1)
洪涛

There is no need to export and then import, using repairDatabase 或者 compact will compress the data. But they have an impact on performance during operation.

The repairDatabase command compacts all collections in the database. It is identical to running the compact command on each collection inpidually.

It should be noted that compact不会像repairDatabasethis will release the disk space that has been applied for, but new disk requests will use the organized space. Another thing to note is that both commands require additional space, see the dick usage section. This means that if the disk space is full, these two commands will not be used. However, at this time, a slave node can be resynchronized and the disk data can be reconstructed.

If you use repairDatabase或者compact in a replica set, it is best to use the rolling method. The method of rolling is to first take out a secondary node and defragment the disk. Then repeat the above steps on all slave nodes. Finally, step down primary and defragment the disk on it. This can avoid the impact of these operations on online services.

Recommended to use usePowerOf2Sizes allows MongoDB to use the disk more efficiently under frequent updates and deletions, because each application and release is a power of 2 in size.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!