避免将整个 blob 加载到内存

Avoiding loading whole blob to memory

我在数据库中存储大文件 (50-500MB)。一旦被应用程序加载,它就不需要内存中的整个文件。我如何将 table 行(或特别是行中的安装程序)直接提取到内存中,同时避免将整个文件加载到 ram(因此是一种缓冲下载到文件中)?

到目前为止,我还没有找到避免加载文件的解决方案。相反,我将请求转发到加载整个文件的烧瓶服务器,然后允许应用程序实例将其下载到文件中。然而,这似乎不是一个很好的解决方案。

您可能正在寻找 FILESTREAM (SQL Server):

FILESTREAM enables SQL Server-based applications to store unstructured data, such as documents and images, on the file system. Applications can leverage the rich streaming APIs and performance of the file system and at the same time maintain transactional consistency between the unstructured data and corresponding structured data.

这很有趣,因为在 SQL 服务器上(对于 Windows)它可以将文件数据流式传输到 Windows 客户端,而无需将它们全部加载到 [=22] 的内存中=] 服务器:

The Win32 streaming support works in the context of a SQL Server transaction. Within a transaction, you can use FILESTREAM functions to obtain a logical UNC file system path of a file. You then use the OpenSqlFilestream API to obtain a file handle. This handle can then be used by Win32 file streaming interfaces, such as ReadFile() and WriteFile(), to access and update the file by way of the file system.

请注意,此时是 not supported on SQL Server 2017 for Linux