Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing a file in a database as opposed to the file system?

Generally, how bad of a performance hit is storing a file in a database (specifically mssql) as opposed to the file system? I can't come up with a reason outside of application portability that I would want to store my files as varbinaries in SQL Server.

like image 305
Cade Avatar asked Aug 12 '08 15:08

Cade


People also ask

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.

Why you should not store files in database?

Files Such as Images Storing a file in a database table means you need to use database logic (and possible application logic) to access the file. This increases the size of your database and degrades its performance. It also makes backups and data corruption harder to deal with.

Why do we store files in database?

Then why store files in DB ? DB provides ACID compliance(Atomicity, Consistency, Isolation, Durability) for each row. DB provides data integrity between the file and its metadata. Database Security is available by default.


1 Answers

Have a look at this answer:

Storing Images in DB - Yea or Nay?

Essentially, the space and performance hit can be quite big, depending on the number of users. Also, keep in mind that Web servers are cheap and you can easily add more to balance the load, whereas the database is the most expensive and hardest to scale part of a web architecture usually.

There are some opposite examples (e.g., Microsoft Sharepoint), but usually, storing files in the database is not a good idea.

Unless possibly you write desktop apps and/or know roughly how many users you will ever have, but on something as random and unexpectable like a public web site, you may pay a high price for storing files in the database.

like image 165
Michael Stum Avatar answered Sep 22 '22 14:09

Michael Stum