删除mongodb的日志文件是否安全? [英] Is it safe to delete the journal file of mongodb?

查看:670
本文介绍了删除mongodb的日志文件是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果删除3.1G日记文件,则sudo service mongodb restart将失败.但是,此文件占用太多空间.我怎么解决这个问题?如何删除它?

If I delete the 3.1G journal file, sudo service mongodb restart will fail. However, this file is taking too much space. How can I solve this problem? How can I remove it?

bash$ du -sh /var/lib/mongodb/*
4.0K    _tmp
65M auction_development.0
128M    auction_development.1
17M auction_development.ns
3.1G    journal
4.0K    mongod.lock

推荐答案

TL; DR:您有两个选择.将MongoDB启动到将日记文件的大小限制为时,请使用--smallfiles启动选项. 128MB,或使用--nojournal选项关闭日志记录.在生产中使用--nojournal通常不是一个好主意,并且在开发中也使用不同的写关注点通常很有意义,因此您在dev和prod中没有不同的代码.

TL;DR: You have two options. Use the --smallfiles startup option when starting MongoDB to limit the size of the journal files to 128MB, or turn off journalling using the --nojournal option. Using --nojournal in production is usually a bad idea, and it often makes sense to use different write concerns also in development so you don't have different code in dev and prod.

详细答案: 不,删除日志文件是不安全的.日记的想法是这样的:

The long answer: No, deleting the journal file isn't safe. The idea of journalling is this:

有一个写操作进来.现在,要使该写操作持久化(并使数据库具有持久性),写操作必须以某种方式进入磁盘.

A write comes in. Now, to make that write persistent (and the database durable), the write must somehow go to the disk.

不幸的是,与写入RAM相比,写入磁盘需要,因此数据库处于两难境地:不写磁盘有风险,因为意外关机会导致数据丢失.但是,每执行一次写入操作就向磁盘写入数据将严重降低数据库的性能,以致无法用于实际目的.

Unfortunately, writes to the disk take eons compared to writes to the RAM, so the database is in a dilemma: not writing to the disk is risky, because an unexpected shutdown would cause data loss. But writing to the disk for every single write operation will decrease the database's performance so badly that it becomes unusable for practical purposes.

现在,数据库将不再追加写入数据文件本身,也不是针对每个请求执行此操作,而是会简单地追加到日记文件中,在日记文件中存储尚未提交给实际数据文件的所有操作.这要快得多,因为文件一直被读写,因此它已经很热"了,它只是一个文件,而不是一堆文件,最后,因为它每隔100ms批量写入所有待处理的操作默认情况下.在某些情况下删除此文件会造成严重破坏.

Now instead of writing to the data files themselves, and instead of doing it for every request, the database will simply append to a journal file where it stores all the operations that haven't been committed to the actual data files yet. This is a lot faster, because the file is already 'hot' since it's read and written to all the time, and it's only one file, not a bunch of files, and lastly, because it writes all pending operations in a batch every 100ms by default. Deleting this file in the middle of something wreaks havoc.

这篇关于删除mongodb的日志文件是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆