serve my text from the filesystem instead of a database? serve my text from the filesystem instead of a database? database database

serve my text from the filesystem instead of a database?


The major advantage you'll get from not using the filesystem is that the database will manage concurrent access properly.Let's say 2 processes need to modify the same text as the same time, synchronisation with the filesystem may lead to race conditions, whereas you will have no problem at all with everyhing in database.


I think your benchmark results will depend on how you store the text data in your database.If you store it as LOB then behind the scenes it is stored in an ordinary file.With any kind of LOB you pay the Database lookup + File IO anyway.

VARCHAR is stored in the tablespace

Ordinary text data types (VARCHAR et al) are very limited in size in typical relational database systems. Something like 2000 or 4000 (Oracle) sometimes 8000 or even 65536 characters. Some databases support long textbut these have serious drawbacks and are not recommended.

LOBs are references to file system objects

If your text is larger you have to use a LOB data type (e.g. CLOB in Oracle).

LOBs usually work like this:The database stores only a reference to a file system object.The file system object contains the data (e.g. the text data).This is very similar to what your colleague proposes except the DBMS lifts the heavy work ofmanaging references and files.

The bottom line is:If you can store your text in a VARCHAR then go for it.If you can't you have two options: Use a LOB or store the data in a file referenced from the database. Both are technically similar and slower than using VARCHAR.


I did this before. Its a mess, you need to keep the filesystem and the database synchronized all the time, so that makes the programming more complicated, as you would guess.My advice is either go for an all filesystem solution, or all database solution, depending on the data. Notably, if you require lots of searches, conditional data retrieval, then go for database, otherwise fs.Note that database may not be optimized for storage of large binary files. Still, remember, if you use both, youre gonna have to keep them synchronized, and it doesnt make for an elegant nor enjoyble (to program) solution.Good luck!