日志系统,突然从24号之后的都断层了,交易看不见。查了一下问题是MongoDB把硬盘撑爆了,看了下情况:

-bash-3.2$ du -h
82M ./log
.1G ./db/journal
.0K ./db/ciflogs/_tmp
.0G ./db/ciflogs
.0K ./db/local/_tmp
.1G ./db/local
.0K ./db/_tmp
.1G ./db
.2G .

去google了两把,又去官网看了下,发现官网FAQ中有一段回答:(注意加粗部分)

Why are the files in my data directory larger than the data in my database?

  • Preallocated data files.

    In the data directory, MongoDB preallocates data files to a particular size, in part to prevent file system fragmentation. MongoDB names the first data file <databasename>.0, the next <databasename>.1, etc. The first file mongodallocates is 64 megabytes, the next 128 megabytes, and so on, up to 2 gigabytes, at which point all subsequent files are 2 gigabytes. The data files include files with allocated space but that hold no data. mongod may allocate a 1 gigabyte data file that may be 90% empty. For most larger databases, unused allocated space is small compared to the database.

    On Unix-like systems, mongod preallocates an additional data file and initializes the disk space to 0. Preallocating data files in the background prevents significant delays when a new database file is next allocated.

    You can disable preallocation with the noprealloc run time option. However noprealloc is not intended for use in production environments: only use noprealloc for testing and with small data sets where you frequently drop databases.

    On Linux systems you can use hdparm to get an idea of how costly allocation might be:

    time hdparm --fallocate $((1024*1024)) testfile
    
  • The oplog.

    If this mongod is a member of a replica set, the data directory includes the oplog.rs file, which is a preallocated capped collection in the local database. The default allocation is approximately 5% of disk space on 64-bit installations, seeOplog Sizing for more information. In most cases, you should not need to resize the oplog. However, if you do, seeChange the Size of the Oplog.

  • The journal.

    The data directory contains the journal files, which store write operations on disk prior to MongoDB applying them to databases. See Journaling Mechanics.

  • Empty records.

    MongoDB maintains lists of empty records in data files when deleting documents and collections. MongoDB can reuse this space, but will never return this space to the operating system.

    To de-fragment allocated storage, use compact, which de-fragments allocated space. By de-fragmenting storage, MongoDB can effectively use the allocated space. compact requires up to 2 gigabytes of extra disk space to run. Do not use compact if you are critically low on disk space.

    Important

    compact only removes fragmentation from MongoDB data files and does not return any disk space to the operating system.

    http://docs.mongodb.org/manual/faq/storage/

然后在Journaling Mechanics页面又有详细对于Journa的介绍:

Journal Files

With journaling enabled, MongoDB creates a journal directory within the directory defined by dbpath, which is /data/db by default. The journal directory holds journal files, which contain write-ahead redo logs. The directory also holds a last-sequence-number file. A clean shutdown removes all the files in the journal directory.

Journal files are append-only files and have file names prefixed with j._. When a journal file holds 1 gigabyte of data, MongoDB creates a new journal file. Once MongoDB applies all the write operations in the journal files, it deletes these files. Unless you write many bytes of data per-second, the journal directory should contain only two or three journal files.

To limit the size of each journal file to 128 megabytes, use the smallfiles run time option when starting mongod.

To speed the frequent sequential writes that occur to the current journal file, you can ensure that the journal directory is on a different filesystem.

Important

If you place the journal on a different filesystem from your data files you cannot use a filesystem snapshot alone to capture valid backups of a dbpath directory. In this case, use fsyncLock() to ensure that database files are consistent before the snapshot and fsyncUnlock() once the snapshot is complete.

Note

Depending on your filesystem, you might experience a preallocation lag the first time you start a mongod instance with journaling enabled.

MongoDB may preallocate journal files if the mongod process determines that it is more efficient to preallocate journal files than create new journal files as needed. The amount of time required to pre-allocate lag might last several minutes, during which you will not be able to connect to the database. This is a one-time preallocation and does not occur with future invocations.

http://docs.mongodb.org/manual/core/journaling/

文中可以看出,journa最多只有3个文件。也就是最大只会占用3G硬盘,而且停止之后会自动删除。启动时使用-smallfiles则会让mongo的journa最大128M。

另外删除的纪录不会立刻释放硬盘,但会在下次写入的时候重新利用。

OK,停一下Mongo,删掉journa,用smallfiles参数。另外删掉一些太早的日志纪录。

mongoDB文件太大查错纪录的更多相关文章

  1. 生成的API分析文件太大。我们无法在交付前验证您的API使用信息。这只是通知信息。

    这次使用了APICloud平台来开发移动APP, 发布的时候在api控制台云编译成ipa后,这次使用apple提供的Application Loader工具提交apa文件到iTunes上去,提交结束的 ...

  2. Sqlserver2005日志文件太大,使其减小的方法

    Sqlserver2005日志文件太大,使其减小的方法: 运行下面的三行 dbName为数据库名: backup log dbNamewith NO_LOG backup log dbNamewith ...

  3. ORACLE 监听日志文件太大停止写监听日志引起数据库连接不上问题

    生产库监听日志文件太大(达到4G多),发现oracle停止写监听日志,检查参数log_file,log_directory,log_status 均正常,数据库运行也正常. 经确认确实为监听日志过大引 ...

  4. apache日志文件太大的问题

    apache日志文件太大的问题 处理Apache日志的两种方法 rotatelogs 是 Apache 2.2 中自带的管道日志程序 rotatelogs [ -l ] logfile [ rotat ...

  5. Mysql文件太大导入失败解决办法总结

    Mysql文件太大导入失败解决办法总结 在使用phpmyadmin导入数据库的时候可能会碰到由于数据库文件太大而无法导入的问题! 英文提示如下:File exceeds the maximum all ...

  6. jvm内存快照dump文件太大,怎么分析

    1.场景 通常,使用eclipse的mat图形化工具打开dump的时候都会内存溢出. 对于比较小的dump,eclipse可以打开,但一旦dump文件太大,eclipse就有点束手无策. 这时候怎么办 ...

  7. [转]MySql ibdata1文件太大如何缩小

    From : http://blog.chinaunix.net/uid-24373487-id-4223322.html 原文地址:MySql ibdata1文件太大如何缩小 作者:emailwht ...

  8. 解决asp.net上传文件时文件太大导致的错误

    即使在web.config中添加了节点和设置依然是不行的,还是报文件太大的错误, <httpModules>       <add name="UploadHttpModu ...

  9. /var/adm/wtmp文件太大该怎么办?

    /var/admin/wtmp文件记录所有用户的登陆信息,随着时间会增长到很大,/var/adm/wtmp文件太大该怎么办呢?先来看看/var/adm/wtmp文件的属性:testterm1:/#ls ...

随机推荐

  1. left join, right join , inner join, join, union的意义

    数据库在连接两张或以上的表来返回数据时,都会生成一张中间的临时表,然后再将临时表返回给用户left join,right join,inner join, join 与 on 配合用 select c ...

  2. 解决修改SQL SERVER 默认1433端口 访问出错的问题;

    1. 如何修改 数据库默认的 1433端口: SQL SERVER 配置管理器中 SQLSERVER 网络配置 xxx数据实例的协议中的  TCP/IP 中 默认端口 都修改为 自己定义的端口 例如 ...

  3. Swift(二,元组,可选类型,类型转化)

    一,首先,元组是Swift中特有的,OC中没有元组相关类型,具体怎么用,看下面的例子吧 //1.使用元组来定义一组数据 let infoTuple = (,1.8) let nameTuple = i ...

  4. Consistent Hashing原理与实现

    原理介绍: consistent hashing原理介绍来自博客:http://blog.csdn.net/sparkliang/article/details/5279393, 多谢博主的分享 co ...

  5. 怎么利用ultraISO对一个文件夹制作ISO镜像

    1. 运行UltraISO软件,选择好需要转换成ISO的文件,直接拖到UltraISO的界面中. 2.点击“另存为”按钮,选择存放路径并写上ISO文件的名称,文件保存类型选择为ISO格式,点击“保存” ...

  6. githubRepository -- 使用

    1. 注册github账号; 2. 配置SSH keys; 点击setting, 配置 SSH keys Generating SSH keys 检查本地的 SSH keys: a> 在用户目录 ...

  7. Python连接Redis连接配置

    1. 测试连接: Python 2.7.8 (default, Oct 20 2014, 15:05:19) [GCC 4.9.1] on linux2 Type "help", ...

  8. Linux技术修复

    今天在慕课网上学习了Linux的一些知识: 我使用命令: ***:~$ route add default gw 192.168.1.1 添加了一个网关:192.168.1.1之后的结果为: ***: ...

  9. 【技术贴】三星Note8 N5100实用教程,关闭相机快门声,增加浏览器退出按钮。

    需要root 增加快门声按钮: 在\system\csc\目录下,有个others.xml的手机功能定制文件,用root explorer之类可以修改系统文件权限的文本修改工具编辑它,在文件最末添加这 ...

  10. 完美卸载SQL Server 2008的方案

    转自完美卸载SQL Server 2008的方案 针对SQL数据库卸载不完全的现象,做了如下总结:   1,控制面板 卸载   首先,打开控制面板,按照"安装时间"进行排序,卸载S ...