How to store videos in a PostgreSQL database? How to store videos in a PostgreSQL database? database database

How to store videos in a PostgreSQL database?


I would generally not recommend to store huge blobs (binary large objects) inside PostgreSQL if referential integrity is not your paramount requirement. Storing huge files in the filesystem is much more efficient:
Much faster, less disk space used, easier backups.

I have written a more comprehensive assessment of the options you've got in a previous answer to a similar question. (With deep links to the manual.)


We did some tests about practical limits of bytea datatype. There are theoretical limit 1GB. But practical limit is about 20MB. Processing larger bytea data eats too much RAM and encoding and decoding takes some time too. Personally I don't think so storing videos is good idea, but if you need it, then use a large objects - blobs.


Without knowing what programming language you are using, I can only give a general approach:

  • Create a table with a column of type 'bytea'.
  • Get the contents of the video file into a variable.
  • Insert a row into that table with that variable as the data for the bytea column.