所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。
你认为优点和缺点是什么?
所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。
你认为优点和缺点是什么?
当前回答
不,因为页面分割。实际上,您定义的行可以是1KB - n MB,因此数据库的页面中会有大量空白,这对性能不利。
其他回答
我负责一些管理许多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
尝试使用SQL模拟文件系统通常是一个糟糕的计划。如果您坚持使用文件系统作为外部存储,那么最终编写的代码会更少,结果也会更好。
关于这个话题,这里有一份有趣的白皮书。
是否使用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.
正如其他人所说,SQL 2008提供了一个Filestream类型,允许您将文件名或标识符作为指针存储在db中,并自动将图像存储在您的文件系统中,这是一个很好的场景。
如果您使用的是较旧的数据库,那么我会说,如果您将其存储为blob数据,那么您将无法通过搜索特性的方式从数据库中获得任何内容,因此最好将地址存储在文件系统上,并以这种方式存储图像。
这样还可以节省文件系统上的空间,因为您只会在文件系统上节省确切数量的空间,甚至是压缩的空间。
此外,您可以决定保存一些结构或元素,允许您在文件系统中浏览原始图像而不需要任何db访问,或者将文件批量传输到另一个系统、硬盘驱动器、S3或其他场景—更新程序中的位置,但保留结构,当尝试增加存储空间时,也不需要尝试将图像从db中取出。
也许,它也会允许你抛出一些缓存元素,基于常用的图像url到你的web引擎/程序,所以你也把自己保存在那里。
我最近创建了一个PHP/MySQL应用程序,用于在MySQL表中存储pdf /Word文件(到目前为止每个文件的大小为40MB)。
优点:
上传的文件复制到备份服务器连同其他一切,不需要单独的备份策略(安心)。 设置web服务器稍微简单一些,因为我不需要有一个上传/文件夹,并告诉我所有的应用程序它在哪里。 我可以使用事务进行编辑以提高数据的完整性——我不必担心孤立的和丢失的文件
缺点:
mysqldump现在需要很长时间,因为其中一个表中有500MB的文件数据。 总的来说,与文件系统相比,内存/cpu效率不是很高
我认为我的实现是成功的,它满足了备份需求并简化了项目布局。对于使用该应用程序的20-30人来说,性能还不错。