Re: Filesystem vs. Postgres for images

From: Steve Atkins <steve(at)blighty(dot)com>
To: postgres list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Filesystem vs. Postgres for images
Date: 2004-04-14 15:44:04
Message-ID: 20040414154403.GB18171@gp.word-to-the-wise.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Apr 14, 2004 at 10:15:51PM +0900, Alex wrote:
> Hi,
> is the file system approach really easier and faster? What if you need
> to protect the image data e.g. you dont want users just to just dowload
> the pictures directly from your website?

It can be much faster, if implemented correctly, to put the large
files directly on the filesystem. It makes it a little harder to cluster,
but it can significantly reduce DB overhead.

There's no issue with the users downloading images directly, as you
normally wouldn't mount them directly into the URL namespace. Instead
the URL would point to a script that would lookup the image in the
database, and check permissions. If the user is allowed to load the
image the script will close it's connection to the database, and start
shoveling bytes from the filesystem to the http connection. Most
decent web application platforms have some amount of support for this
sort of thing built in.

That has a number of other advantages too - it can take a long time
for a user to download a large file, and you really don't want the
thread handling them to tie up a database connection for all that
time. If you're on a platform that supports nice things like
sendfile(2) you can even have the kernel do almost all the work.

Cheers,
Steve

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2004-04-14 16:32:13 Donating
Previous Message Tom Lane 2004-04-14 15:26:52 Re: db schema diff