我应该将文件存储在数据库中还是只存储到该文件的位置?
哪个是更好的做法来存储文件?
Which is the better practice to store file? Directly store the file in database or just the location to that file?
当接受答案这么快时,你不会得到
When accept answers so quickly, you do not get the benefit of answers from a larger audience.
这取决于。
-
如果你有一个mickey鼠标免费软件数据库,意味着它不能正确处理blob
If you have a mickey mouse freeware database, meaning that it does not handle blobs appropriately (read the blobs on every SELECT; do not store the blobs in a separate area), keep the files outside.
如果你有一个企业数据库,它是一个企业数据库没有问题,保持数据库内的blob。这些不会在每个SELECT上读取blob。一个额外的读取得到blob不是一个性能问题。
If you have an enterprise database, it is no problem at all to keep the blobs inside the database. These do not read the blobs on every SELECT. The one extra read to get the blob is not a "performance" "problem".
大多数数据库是2k页而不是8k或16k。如果您的页面大小较大,则最后一页的未使用部分(每个blob)会有一点浪费。
Most databases are 2k pages not 8k or 16k. If yours has a larger pagesize, then there will be a bit of waste in the unused portion of the last page, per blob.
blobs在数据库中是你的数据库备份会更大。一些企业数据库注意到页面未更改,并将其从增量备份中排除;
The disadvantage of keeping the blobs in the database is your database backups will be much bigger. Some enterprise databases notice that the page has not changed, and exclude it from the incremental backups; others have no incrementals.
在数据库中保留blob的优点是数据和参照完整性。
The advantage of keeping the blobs in the database is data and referential integrity. You will not have the problem of having the rows out of synch with the blobs.
- 我在去年完成了一项调整,其中cust db中的130GB数据,以及存储在db外部的700GB文档。经过十年的问题,他们咬了一颗子弹,把文件移入db。猜猜什么,应该是一个简单的工作(长但简单),因为参考应该是绝对正确的,最终是大规模的,因为有这么多的重复和无效的引用。结果数据库是630GB,有100GB的重复。 2K pageize。
p>
Responses to Comments
- 斜杠或反斜杠
简单。在数据库中,只存储斜杠。您需要一种识别目标系统的方法,并且IsWindoze
指示符。它应该在表层次结构中更高,而不是在您定位文件名
的级别。如果指示器设置,每当您报告或显示文件名
列时,将斜杠改为反斜杠。
您将有类似的问题, code> DriveLetter 和冒号(Unix没有)。
- Slash or Backslash
Easy. In the database, store slash only. You need a way of identifying the target system, andIsWindoze
indicator. It should be higher up in the table hierarchy, not at the level where you locate theFilename
. If the indicator is set, whenever you report or display theFilename
column, change the slashes to backslashes.
You will have a similar problem with theDriveLetter
and colon, which Unix does not have.