简体   繁体   English

使用 Oracle 10g 保存和检索二进制文件的最佳方法是什么?

[英]What's the best way to save and retrieve binary files with Oracle 10g?

I'm about to implement a feature in our application that allows the user to 'upload' a PDF or Microsoft PowerPoint document, which the application will then make available to other users in a viewer (so they don't get to 'download' it in the 'Save as..' sense).我即将在我们的应用程序中实现一项功能,该功能允许用户“上传”PDF 或 Microsoft PowerPoint 文档,然后应用程序将在查看器中提供给其他用户使用(因此他们无法“下载”它在“另存为..”的意义上)。

I already know how to save and retrieve arbitrary binary information in database columns, but as this will be a commonly used feature of our application I fear that solution would lead to enormously large database tables (as we know one of our customers will want to put video in PowerPoint documents).我已经知道如何在数据库列中保存和检索任意二进制信息,但由于这将是我们应用程序的一个常用功能,我担心该解决方案会导致数据库表非常大(我们知道我们的一个客户会想把PowerPoint 文档中的视频)。

I know there's a way to create a 'directory' object in Oracle, but is there a way to use this feature to store and retrieve binary files saved elsewhere on the Database Server?我知道有一种方法可以在 Oracle 中创建一个“目录”object,但是有没有办法使用此功能来存储和检索保存在数据库服务器上其他地方的二进制文件?

Or am I being overly paranoid about the database size?还是我对数据库大小过于偏执?

(for completeness our application is.Net WinForms using CoreLab / DevArt OraDirect.Net drivers to Oracle 10g) (为了完整起见,我们的应用程序是使用CoreLab / DevArt OraDirect.Net 驱动程序到 Oracle 10g 的.Net WinForms)

Couple of options: You could put the BLOB column in its own tablespace, with its own storage characteristics;几个选项:您可以将 BLOB 列放在自己的表空间中,并具有自己的存储特性; you could store the BLOBs in their own table, linked to the other table by an ID column.您可以将 BLOB 存储在它们自己的表中,并通过 ID 列链接到另一个表。 In either case as you suggested you could define the column as a BFILE which means the actual file is stored externally from the database in a directory.在您建议的任何一种情况下,您都可以将列定义为 BFILE,这意味着实际文件存储在数据库外部的目录中。 What might be a concern there is that BFILE LOBs do not participate in transactions and are not recoverable with the rest of the database.可能需要担心的是,BFILE LOB 不参与事务,并且无法使用数据库的 rest 进行恢复。

This is all discussed in the Oracle 10gR2 SQL reference, chapter 2, starting on page 23.这在 Oracle 10gR2 SQL 参考资料,第 2 章,从第 23 页开始讨论。

I guess it depends what you consider enormously large.我想这取决于你认为非常大的东西。

It really does depend on the use case.它确实取决于用例。 If the documents are only being accessed rarely then putting it in the database would be fine (with the advantage of getting "free" backups, eg, with the database).如果文档很少被访问,那么将其放入数据库中就可以了(具有获得“免费”备份的优势,例如,使用数据库)。

If these are files which are going to be hit over and over again, you might be better to put them directly on disk and just store the location, or even (if its really high bandwidth) look into something like MogileFS如果这些文件会一次又一次地被击中,你可能最好将它们直接放在磁盘上并存储位置,或者甚至(如果它的带宽真的很高)查看MogileFS之类的东西

No one is going to be able to give you a Yes or no answer for this.没有人能够对此给出是或否的答案。

You could use a normal LOB column type and set the storage parameters for that field so it's on a seperate tablespace.您可以使用普通的 LOB 列类型并为该字段设置存储参数,使其位于单独的表空间中。 Create the tablespace somewhere that can handle having huge amounts of data thrown at it and you'll minimise the impact.在某个可以处理大量数据的地方创建表空间,这样可以将影响降到最低。

To be seriously super paranoid about disk usage you could additionally compress the tablespace by marking it as such.要对磁盘使用非常严重,您可以通过将表空间标记为这样来额外压缩表空间。 Something along the lines of:类似于以下内容:

CREATE TABLESPACE binary_data1 DATAFILE some_san_location DEFAULT COMPRESS STORAGE(...) CREATE TABLESPACE binary_data1 DATAFILE some_san_location DEFAULT COMPRESS STORAGE(...)

In my experience, a simple VARCHAR2 field containing the file name of the attachments is a better and easier solution.根据我的经验,包含附件文件名的简单 VARCHAR2 字段是一种更好、更简单的解决方案。 File system size is a lot easier to manage than database size.文件系统大小比数据库大小更容易管理。

The data has to live somewhere, whether it's internal to the DB or whether you just store a link to a (server) accessible file path, you're still chewing space.数据必须存在于某个地方,无论它是在数据库内部还是只是存储到(服务器)可访问文件路径的链接,您仍在咀嚼空间。

I've just used simple LOB fields in the past, it seemed to work fine.我过去只使用过简单的 LOB 字段,它似乎工作正常。 If you keep the data inside the DB at least you keep your backup hassles low - you may have a lot of data to back up but when you restore it, it'll all be there.如果您将数据保存在数据库中,至少可以减少备份的麻烦——您可能有很多数据要备份,但是当您恢复它时,它们都会在那里。 Splitting the binary out means you potentially break the DB or lose data if you're not careful about what you backup.拆分二进制文件意味着如果您不小心备份的内容,您可能会破坏数据库或丢失数据。

One reason to just store the link or an ID that can be used to build the link is that the storage that you usually use for Oracle DB's is rather expensive.仅存储链接或可用于构建链接的 ID 的一个原因是,您通常用于 Oracle DB 的存储相当昂贵。 If you have lots of large files, it is usually much more cost-effective to put them on a less expensive array of disks.如果您有很多大文件,将它们放在成本较低的磁盘阵列上通常更具成本效益。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM