Thread: Storage of Binary Data
I have a somewhat philosophical question about best practices when storing binary data.<br /><br />For my web projects, wehave been storing binary data (like images, PDF's, etc) on the hard drive of the web server instead of the database. Withinthe database, we keep information, like whether an image is present, in a separate column. <br /><br />For example:<br/><br />CREATE TABLE site_user (<br /> site_user_id BIGSERIAL NOT NULL,<br /> has_profile_image BOOLEAN DEFAULTfalse NOT NULL<br /> CONSTRAINT site_user_pkey PRIMARY KEY (site_user_id)<br />);<br /><br />And then store theprofile image at: <br /><br /> [web root]/images/siteuserprofile/profile-[site_user_id here].jpg<br /><br />We alsohave a back end process that then checks these files into CVS to help maintain version control.<br /><br />My questionsare:<br />* What other options are people using to store data like this? <br />* What are the advantages/disadvantagesof these storage methods?<br /><br />I have been very reluctant to store the binary data in the databasefor the following reasons:<br />* Performance because you cannot just save the data to the file system, you must<br /> interact with the database to get/save contents<br />* Increases complexity of application<br />* I have hadproblems with saving binary data using JDBC before (that was with<br /> Oracle 7 though)<br clear="all" />* I am concernedabout how well the data backups will work - there have been several <br /> people who have had problems with backingup and restoring binary data on this<br /> list<br /><br />I am trying to develop some best practices so any inputyou guys have is welcome!<br /><br />Thanks<br /><br />==================================================================<br /> Aaron Bono<br /> Aranya Software Technologies,Inc.<br /> <a href="http://www.aranya.com">http://www.aranya.com</a><br />==================================================================
> For my web projects, we have been storing binary data (like images, PDF's, > etc) on the hard drive of the web server instead of the database. Within > the database, we keep information, like whether an image is present, in a > separate column. In most cases, this is probably the best approach. It has the problem that COMMITs of this data aren't atomic (the file write could succeed and the database write fail, for example). But that can usually be worked around, and at least you're not bulking your database with binaries. A -- Andrew Sullivan | ajs@crankycanuck.ca This work was visionary and imaginative, and goes to show that visionary and imaginative work need not end up well. --Dennis Ritchie