所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。
你认为优点和缺点是什么?
所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。
你认为优点和缺点是什么?
当前回答
The word on the street is that unless you are a database vendor trying to prove that your database can do it (like, let's say Microsoft boasting about Terraserver storing a bajillion images in SQL Server) it's not a very good idea. When the alternative - storing images on file servers and paths in the database is so much easier, why bother? Blob fields are kind of like the off-road capabilities of SUVs - most people don't use them, those who do usually get in trouble, and then there are those who do, but only for the fun of it.
其他回答
有一件事我还没有看到任何人提到,但绝对值得注意的是,在大多数文件系统中也存在与存储大量图像相关的问题。例如,如果您采用上面提到的方法,以主键命名每个图像文件,在大多数文件系统上,如果您试图将所有图像放在一个大目录中,一旦您达到了非常大的图像数量(例如数十万或数百万),您将遇到问题。
常见的解决方案是将它们散列到平衡的子目录树中。
如果你需要在文件系统中存储大量的图像,需要考虑以下几点:
备份和恢复。你如何保持图像同步。 文件系统的性能。这取决于您正在做的事情和文件系统,但您可能希望实现一个散列机制,这样您就不会有一个包含数十亿个文件的目录。 复制。您是否需要在多个服务器之间保持文件同步?
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.
到目前为止,这个解决方案工作得很好,因为应用程序本身被定位为桌面上的单个实例。有一个网站将所有这些数据存档,以供在线访问,但我绝不会使用相同的解决方案。我同意文件访问更可取,因为它可以更好地适应图像请求的频率和数量。
希望这不是太多的废话,但我看到了这个主题,并想从一个相对成功的中小型应用程序中提供一些我的见解。
通常,我强烈反对采用基础设施中最昂贵和最难扩展的部分(数据库),并将所有负载都放在其中。另一方面:它极大地简化了备份策略,特别是当你有多个web服务器,需要以某种方式保持数据同步时。
像大多数其他事情一样,这取决于预期的规模和预算。
我个人会将大数据存储在数据库之外。
优点:存储所有东西在一个请,容易访问数据文件,容易备份 缺点:降低数据库性能,很多页面分割,可能导致数据库损坏