Storage of Binary Data

Поиск
Список
Период
Сортировка
Искать

Storage of Binary Data

От:
"Aaron Bono" <postgresql@aranya.com>
Дата:
I have a somewhat philosophical question about best practices when storing binary data.

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.

For example:

CREATE TABLE site_user (
   site_user_id BIGSERIAL NOT NULL,
   has_profile_image BOOLEAN DEFAULT false NOT NULL
   CONSTRAINT site_user_pkey PRIMARY KEY (site_user_id)
);

And then store the profile image at:

   [web root]/images/siteuserprofile/profile-[site_user_id here].jpg

We also have a back end process that then checks these files into CVS to help maintain version control.

My questions are:
* What other options are people using to store data like this?
* What are the advantages/disadvantages of these storage methods?

I have been very reluctant to store the binary data in the database for the following reasons:
* Performance because you cannot just save the data to the file system, you must
   interact with the database to get/save contents
* Increases complexity of application
* I have had problems with saving binary data using JDBC before (that was with
   Oracle 7 though)
* I am concerned about how well the data backups will work - there have been several
   people who have had problems with backing up and restoring binary data on this
   list

I am trying to develop some best practices so any input you guys have is welcome!

Thanks

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
==================================================================

Re: Storage of Binary Data

От:
Andrew Sullivan <ajs@crankycanuck.ca>
Дата:
> 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

FAQ