Benchmark of ways to store files in a PostgreSQL

Some time ago I've presented an article about various ways to store file in a PostgreSQL database, and at the end of the article I've promised a benchmark comparing the ways described. It took me some time, but the benchmark is here ...

Storing files in a PostgreSQL database

This article extends an article about reasons to store user files in a database and not in a filesystem, and describes several ways how to do that in PostgreSQL. There are BLOBs, BYTEA columns, custom solutions, and all of them have advantages / disadvantages, so let's investigate them.

Why to store files in a database

Imagine you are working on a web application that requires storing of files (e.g. a photo gallery). And there comes a question "Should I store the files in a database, or directly on the filesystem?" Maybe you've asked this question on a discussion forum / mailing list and I guess the answer you've received was something like "It's much more efficient to store files outside the database." Well, I'll try to explain why I prefer storing files in a database. This article is based on a discussion I've had with James Lewis, after I posted a question to pg-php mailing list.

1