`
luozhaoyu
  • 浏览: 343460 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

mongo删除大表之后的操作

阅读更多
一直很好奇mongo执行db.collection.drop之后需不需要优化。
所以先查了官方文档:
drop
引用

http://docs.mongodb.org/manual/reference/command/drop/

The drop command removes an entire collection from a database.
Note that this command also removes any indexes associated with the dropped collection.

drop会连索引一块删除

compact
引用

http://docs.mongodb.org/manual/reference/command/compact/

Rewrites and defragments all data in a collection, as well as all of the indexes on that collection.

compact may increase the total size and number of your data files, especially when run for the first time. However, this will not increase the total collection storage space since storage size is the amount of data allocated within the database files, and not the size/number of the files on the file system.

compact requires up to 2 gigabytes of additional disk space while running. Unlike repairDatabase, compact does not free space on the file system.

compact commands do not replicate to secondaries in a replica set:

Compact each member separately.
Ideally run compact on a secondary. See option force:true above for information regarding compacting the primary.

可见compact是一个collection的磁盘碎片整理,且会block整个数据库
compact会增加mongo的磁盘占用(且需要2G临时空间),而repairDatabase可以free space
compact操作不会传播到secondaries上,需要一个一个操作

repairDatabase
引用

The repairDatabase command checks and repairs errors and inconsistencies with the data storage. The command is analogous to a fsck command for file systems.

Note When using journaling, there is almost never any need to run repairDatabase. In the event of an unclean shutdown, the server will be able restore the data files to a pristine state automatically.

As a side effect, the repairDatabase command will compact the database, as the compact command, and also reduces the total size of the data files on disk. The repairDatabase command will also recreate all indexes in the database.

repairDatabase用来检查和修复错误及数据不一致,与fsck相似
打开journal日志之后几乎没有必要再repariDatabase.
repairDatabase副作用是会compact,重建索引和减少磁盘占用


小结:
所以从文档来看,没有直接必要在删大表之后重新repairDatabase。暂时没找到证据说明repairDatabase之后可以提高性能,只是能够把磁盘空间回收而已

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics