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

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


当前回答

我更喜欢将图像路径存储在DB中,并将图像存储在文件系统中(在服务器之间使用rsync以保持所有内容的合理最新)。

然而,我所做的一些内容管理系统的工作需要在CMS中使用图像,原因有几个——可见性控制(因此资产被保留到新闻稿发布之前)、版本控制、重新格式化(一些CMS将动态调整缩略图的大小)以及将图像链接到所见即所得页面的易用性。

因此,我的经验法则是始终将应用程序的内容保存在文件系统中,除非它是CMS驱动的。

其他回答

对于大量的小图像,数据库可能更好。

我有一个带有许多小缩略图的应用程序(每个缩略图2Kb)。当我将它们放到文件系统中时,由于文件系统的块大小,它们每个都消耗了8kb。空间增加了400% !

有关块大小的更多信息,请参阅这篇文章: iphone文件系统的块大小是多少?

正如有人已经提到的,“视情况而定”。如果数据库中的存储被认为是文件系统的1对1替代方案,那么它可能不是最佳选择。

但是,如果数据库后端将提供额外的值,而不仅仅是blob的序列化和存储,那么它可能是真正有意义的。

You may take a look at WKT Raster which is a project aiming at developing raster support in PostGIS which in turn serves as a geospatial extension for PostgreSQL database system. Idea behind the WKT Raster is not only to define a format for raster serialization and storage (using PostgreSQL system), but, what's much more important than storage, is to specify database-side efficient image processing accessible from SQL. Long story short, the idea is to move the operational weight from client to database backend, so it take places as close to storage itself as possible. The WKT Raster, as PostGIS, is dedicate to applications of specific domain, GIS.

要获得更完整的概述,请查看该系统的网站和演示文稿(PDF)。

我负责一些管理许多TB图像的应用程序。我们发现在数据库中存储文件路径是最好的。

这里有几个问题:

database storage is usually more expensive than file system storage you can super-accelerate file system access with standard off the shelf products for example, many web servers use the operating system's sendfile() system call to asynchronously send a file directly from the file system to the network interface. Images stored in a database don't benefit from this optimization. things like web servers, etc, need no special coding or processing to access images in the file system databases win out where transactional integrity between the image and metadata are important. it is more complex to manage integrity between db metadata and file system data it is difficult (within the context of a web application) to guarantee data has been flushed to disk on the filesystem

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

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

No.

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

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

这取决于你要存储的图像数量和它们的大小。我曾经使用数据库存储图像,我的经验是相当不错的。

在我看来,使用数据库存储图像的优点是,

A.你不需要FS结构来保存你的图像 B.当存储更多的项时,数据库索引比FS树执行得更好 C.智能调优的数据库在缓存查询结果方面表现良好 D.备份很简单。如果您设置了复制,并且内容从用户附近的服务器传递,那么它也可以很好地工作。在这种情况下,不需要显式同步。

如果你的图像很小(比如< 64k),并且你的db的存储引擎支持内联(记录中)blob,它可以进一步提高性能,因为不需要间接(实现了引用的局部性)。

当您处理少量大尺寸图像时,存储图像可能是一个坏主意。在db中存储图像的另一个问题是,像创建、修改日期这样的元数据必须由应用程序处理。