当我从 /data/db 中删除所有文件时,为什么会保存 MongoDB 数据?

发布于 2024-10-08 19:08:42 字数 241 浏览 10 评论 0原文

我刚刚开始在 Rails 3 中使用 MonogDB。在做了一些基准测试之后,我发现它的执行速度比 Postgresql/pg 快 5-10 倍。

我决定检查数据的存储方式,因此我从 /data/db 中删除了所有文件(该文件夹包含“mydb.0”、“mydb.1”等文件。

但是我仍然可以从 Rails 应用程序访问数据即使在重新加载服务器之后,

是否有任何类型的临时或缓存文件夹包含所有包含数据的 .json 文件?

I just started using MonogDB with Rails 3. After doing some benchmarks, I found out that it performs 5-10 times faster than Postgresql/pg.

I decided to check how the data is stored, so I removed all the files from /data/db (that folder contained files like "mydb.0", "mydb.1" etc.

However I still can access data from my Rails app! Even after reloading the server.

So is there any kind of temp or cache folder with all the .json files with data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两相知 2024-10-15 19:08:42
  1. 在不停止 MongoDB 的情况下无法删除“数据文件”。
  2. MongoDB 使用 缓存,但如果 MongoDB 停止,缓存日期也会清空。
  3. 如果您停止 MongoDB 并删除数据文件夹,则无法再访问数据。
  4. MongoDB 将所有数据保存为 bson,而不是 json。
  1. You can't delete 'data files' without stopping MongoDB.
  2. MongoDB uses caching, but in case when MongoDB was stopped cached date also emptied.
  3. If you stopped MongoDB and removed the data folder, the data is no longer accessible.
  4. MongoDB saves all data as bson, not as json.
梦在深巷 2024-10-15 19:08:42

正确答案是这是 UNIX 功能,而不是 mongo。 (我假设你使用的是 Linux)

Mongo 使用内存映射文件作为存储。除其他外,这意味着 mongo 很可能始终保持所有文件打开。

在 Unix 上,一旦使用文件的最后一个进程关闭文件,文件就会被删除,而不是在您发出“rm”命令时。

在这种情况下,rm 命令取消文件链接(从目录中删除条目,因此无法再次访问)。

所以,答案是,一旦停止 mongo,该文件就会被操作系统删除。

请注意,该文件仍在使用磁盘空间,即使“df”或“du”表示不是。这可能会令人困惑,因为您可能会出现“磁盘已满”错误,并在“df”上报告大量可用空间。

您可以删除此文件,但是:

  • 您不会真正释放空间,但所有 Unix 命令都会认为相反。
  • Mongo不会受到影响(乍一看,不太了解内部原理),但关闭时所有数据都会丢失。有时这很有用。 (我曾经看到这个用于设置演示服务器)

The correct answer is that this is a UNIX feature, not mongo. (I presume you are using Linux)

Mongo uses memory mapped files as a store. Among other things this means that most probably mongo keeps all the files open all the time.

On Unix, the files are removed as soon as the last process using the files closes them, not when you issue the "rm" command.

In this case, the rm command unlinks the file (Removes the entry from the directories, so cannot be accessed again).

So, the answer is that the file will be removed by the OS as soon as you stop mongo.

Note that the file is still using disk space, even if "df" or "du" says is not. This can be confusing as you can have "disk full" errors with lots of free space reported on "df".

You can delete this files but:

  • You will not really free up space, but all Unix commands will think the oposite.
  • Mongo will not be affected (At first sight, don't really know the internals), but all data will be lost on close. Which can be usefull sometimes. (I saw this once used to setup demo servers)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文