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

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


当前回答

SQL Server 2008提供了一个两者兼备的解决方案:文件流数据类型。

像管理普通表一样管理它,并具有文件系统的性能。

其他回答

I'm not sure how much of a "real world" example this is, but I currently have an application out there that stores details for a trading card game, including the images for the cards. Granted the record count for the database is only 2851 records to date, but given the fact that certain cards have are released multiple times and have alternate artwork, it was actually more efficient sizewise to scan the "primary square" of the artwork and then dynamically generate the border and miscellaneous effects for the card when requested.

这个图像库的最初创建者创建了一个数据访问类,它根据请求呈现图像,并且对于查看和单独的卡片来说,它的速度非常快。

This also eases deployment/updates when new cards are released, instead of zipping up an entire folder of images and sending those down the pipe and ensuring the proper folder structure is created, I simply update the database and have the user download it again. This currently sizes up to 56MB, which isn't great, but I'm working on an incremental update feature for future releases. In addition, there is a "no images" version of the application that allows those over dial-up to get the application without the download delay.

到目前为止,这个解决方案工作得很好,因为应用程序本身被定位为桌面上的单个实例。有一个网站将所有这些数据存档,以供在线访问,但我绝不会使用相同的解决方案。我同意文件访问更可取,因为它可以更好地适应图像请求的频率和数量。

希望这不是太多的废话,但我看到了这个主题,并想从一个相对成功的中小型应用程序中提供一些我的见解。

在数据库中只存储映像的文件路径的问题是,不能再强制数据库的完整性。

如果文件路径所指向的实际映像变得不可用,则数据库会不知不觉地出现完整性错误。

考虑到图像是被寻找的实际数据,并且它们可以在一个集成的数据库中更容易地管理(图像不会突然消失),而不必与某种文件系统(如果文件系统是独立访问的,图像可能会突然“消失”),我倾向于将它们直接存储为BLOB或类似的文件系统。

文件存储。Facebook的工程师们对此进行了热烈的讨论。一个收获是了解目录中文件的实际限制。

大海捞针:高效存储数十亿张照片

关于这个话题,这里有一份有趣的白皮书。

是否使用BLOB:数据库或文件系统中的大型对象存储

答案是“视情况而定。”当然,这取决于数据库服务器及其blob存储方法。它还取决于存储在blob中的数据类型,以及如何访问这些数据。

使用数据库作为存储机制,可以有效地存储和传递较小的文件。较大的文件可能最好使用文件系统存储,特别是如果它们将经常被修改/更新。(blob碎片在性能方面成为一个问题。)

Here's an additional point to keep in mind. One of the reasons supporting the use of a database to store the blobs is ACID compliance. However, the approach that the testers used in the white paper, (Bulk Logged option of SQL Server,) which doubled SQL Server throughput, effectively changed the 'D' in ACID to a 'd,' as the blob data was not logged with the initial writes for the transaction. Therefore, if full ACID compliance is an important requirement for your system, halve the SQL Server throughput figures for database writes when comparing file I/O to database blob I/O.

在我当前的应用程序中,我两者都在做。当用户确定要附加到记录上的图像时,我使用ImageMagick将其调整为适合在屏幕上显示的大小(对于我的应用程序约为300x300),并将其存储在数据库中以方便访问,但随后还将用户的原始文件复制到网络共享,以便它可用于需要更高分辨率的应用程序(如打印)。

(还有一些其他的因素:Navision将只显示BMP,所以当我调整它的大小时,我也转换为BMP存储,数据库被复制到远程站点,在那里能够显示图像是有用的。打印工作只在总部进行,所以我不需要复制原始文件。