所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。

你认为优点和缺点是什么?


当前回答

在数据库中存储图像仍然意味着图像数据最终位于文件系统中的某个位置,但被遮蔽,因此您不能直接访问它。

+压力:

数据库的完整性 它易于管理,因为您不必担心在添加或删除映像时保持文件系统同步

-维斯:

性能损失——数据库查找通常比文件系统查找慢 您不能直接编辑图像(裁剪,调整大小)

这两种方法都是常见的和实践的。看看优点和缺点。无论哪种方式,你都必须考虑如何克服缺点。在数据库中存储通常意味着调整数据库参数并实现某种缓存。使用文件系统要求您找到某种保持文件系统+数据库同步的方法。

其他回答

如果你需要在文件系统中存储大量的图像,需要考虑以下几点:

备份和恢复。你如何保持图像同步。 文件系统的性能。这取决于您正在做的事情和文件系统,但您可能希望实现一个散列机制,这样您就不会有一个包含数十亿个文件的目录。 复制。您是否需要在多个服务器之间保持文件同步?

不经常编辑的小静态图像(不超过几兆)应该存储在数据库中。这种方法有几个好处,包括更容易移植(图像与数据库一起传输),更容易备份/恢复(图像与数据库一起备份)和更好的可伸缩性(一个包含数千个小缩略图文件的文件系统文件夹对我来说听起来像是可伸缩性的噩梦)。

从数据库提供图像很简单,只需实现一个http处理程序,将从DB服务器返回的字节数组作为二进制流提供服务。

这里的诀窍是不要成为一个狂热分子。

这里需要注意的一点是,在专业文件系统阵营中没有人列出特定的文件系统。这是否意味着从FAT16到ZFS可以轻松击败所有数据库?

No.

事实上,许多数据库都胜过许多文件系统,即使我们只讨论原始速度。

正确的做法是为您的精确场景做出正确的决定,要做到这一点,您需要一些数字和一些用例估计。

根据我的经验,有时最简单的解决方案是根据主键来命名图像。因此,很容易找到属于特定记录的图像,反之亦然。但与此同时,你并没有在数据库中存储图像的任何信息。

I have worked with many digital storage systems and they all store digital objects on the file system. They tend to use a branch approach, so there will be an archive tree on the file system, often starting with year of entry e.g. 2009, subdirectory will be month e.g. 8 for August, next directory will be day e.g. 11 and sometimes they will use hour as well, the file will then be named with the records persistent ID. Using BLOBS has its advantages and I have heard of it being used often in the IT parts of the chemical industry for storing thousands or millions of photographs and diagrams. It can provide more granular security, a single method of backup, potentially better data integrity and improved inter media searching, Oracle has many features for this within the package they used to call Intermedia (I think it is called something else now). The file system can also have granular security provided through a system such as XACML or another XML type security object. See D Space of Fedora Object Store for examples.