Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing files in database Vs file system

Tags:

one of my customer ask for a Document Management System for some thousands of document in different format i.e. pdf, doc, docx etc. My question is what is the best way to store this file in database or in file system? How easy to secure a document between the two approach?.

Fast retrieval of the files is the key requirement..

am using mysql if that helps

Regards.

like image 268
Sam Samson Avatar asked Aug 04 '11 09:08

Sam Samson


People also ask

Should I store files in database or filesystem?

In my own experience, it is always better to store files as files. The reason is that the filesystem is optimised for file storeage, whereas a database is not.

Why is it better to store data in a database rather than in the file system?

Data sharing: The file system does not allow sharing of data or sharing is too complex. Whereas in DBMS, data can be shared easily due to a centralized system. Data concurrency: Concurrent access to data means more than one user is accessing the same data at the same time.

Is it good to store files in database?

Storing files in the database slows down overall query performance simply because there is more data transmitted between the application and the database. Additionally, files use up RAM which is used internally by the database to improve performance.

What is the difference between database and files in file system?

A File System is a collection of raw data files stored in the hard-drive, whereas a database is intended for easily organizing, storing and retrieving large amounts of data. In other words, a database holds a bundle of organized data typically in a digital form for one or more users.


2 Answers

You might want to store it directly into filesystem.

When using filesystem careful with :

  • Confidentiality : Put documents outside of your Apache Document Root. Then a PHP Controller of yours will output documents.
  • Sharded path : do not store thousands of documents in the same directory, make differents directories. You can shard with a Hash on the Filename for example. Such as /documents/A/F/B/AFB43677267ABCEF5786692/myfile.pdf.
  • Inode number : You can run out of inodes if you store a lot of small files (might not be your case if storing mostly PDF and office documents).

If you need to search for these documents (date/title/etc...) you may want to store metadata into a database for better performances.

FYI, in this question MS SQL Server has FILESYSTEM column type (like an hybrid), but at the moment MySQL doesn't have an alternative.

like image 78
Sébastien VINCENT Avatar answered Oct 25 '22 05:10

Sébastien VINCENT


Using filesystem access for big datablobs means in general faster access and less overhead than storing them in a mysql database.

One interesting and possibly related post: Storing Images in DB - Yea or Nay?

like image 34
Johan Avatar answered Oct 25 '22 06:10

Johan