9

I am storing image files (like jpg, png) in a PostgreSQL database. I found information on how to do that here.

Likewise, I want to store videos in a PostgreSQL database. I searched the net - some say one should use a data type such as bytea to store binary data.

Can you tell me how to use a bytea column to store videos?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
sat
  • 14,589
  • 7
  • 46
  • 65
  • As far as I know, there is no `IMAGE` type in PostgreSQL, unless you've created it with `CREATE TYPE` yourself (presumably based on `BYTEA`). How would storing a video be different from storing an image? – Bruno Jan 23 '12 at 11:13
  • sorry,don't mistake me..i don't want to store the videos an image.I want to store video in database by using bytea. – sat Jan 23 '12 at 11:19

3 Answers3

17

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.)

Community
  • 1
  • 1
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
9

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.

Pavel Stehule
  • 42,331
  • 5
  • 91
  • 94
0

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.
zgpmax
  • 2,777
  • 15
  • 22