As far as PostgreSQL is concerned, type text
is out of the question. It is slower, uses more space and is more error-prone than bytea
for the purpose.
There are basically 3 approaches:
Use type bytea
(basically the pg equivalent of the SQL blob type).
Use "large objects".
Store blobs as files in the filesystem and only store the filename
in the database.
Each has it's own advantages and disadvantages.
1. is rather simple to handle but needs the most disk space. Some decoding and encoding is required, which makes it also slow-ish. Backups grow rapidly in size!
2. is slightly awkward in handling, but you have your own infrastructure to manipulate the blobs - if you should need that. And you can more easily make separate backups.
3. is by far the fastest way and uses the least disk space. But it does not provide the referential integrity that you get when you store inside the database.
I have a number of implementations like that for image files: store a small thumbnail in a bytea-field for referential integrity and quick reference. Store the original image as file in the file-system. Of course, you need to put some thought into when and how to delete outdated files, how to backup the external files and such.