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

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


当前回答

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

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

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

其他回答

我负责一些管理许多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

没有人提到的是DB保证原子操作、事务完整性和处理并发性。对于文件系统,甚至引用完整性都不存在了——那么您如何知道您的文件名仍然是正确的呢?

如果你的文件系统中有你的图像,当你写一个新版本甚至删除文件时,有人正在读取文件-会发生什么?

我们使用blob是因为它们也更容易管理(备份、复制、传输)。他们为我们工作得很好。

正如有人已经提到的,“视情况而定”。如果数据库中的存储被认为是文件系统的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)。

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

+压力:

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

-维斯:

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

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

我几乎从不把它们存储在数据库中。最好的方法通常是将映像存储在一个由中央配置变量控制的路径中,并根据DB表和主键(如果可能的话)命名映像。这给了你以下优势:

通过更新全局配置,将映像移动到另一个分区或服务器。 通过搜索图像的主键来查找与图像匹配的记录。 您的图像可以访问处理工具,如imagemagick。 在web应用程序中,您的图像可以由web服务器直接处理(节省处理)。 CMS工具和Coldfusion等网络语言可以处理本地上传。