Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store videos in a PostgreSQL database?

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?

like image 809
sat Avatar asked Jan 23 '12 11:01

sat


People also ask

Can you store files in PostgreSQL database?

You can store the data right in the row or you can use the large object facility. Since PostgreSQL now uses something called TOAST to move large fields out of the table there should be no performance penalty associated with storing large data in the row directly.

How do I store objects in PostgreSQL?

PostgreSQL provides two distinct ways to store binary data. Binary data can be stored in a table using the data type bytea or by using the Large Object feature which stores the binary data in a separate table in a special format and refers to that table by storing a value of type oid in your table.

Is PostgreSQL good for time series?

Postgres' built-in partitioning is super useful for managing time series data. By partitioning your Postgres table on a time column by range (thereby creating a time-partitioned table), you can have a table with much smaller partition tables and much smaller indexes on those partitions—instead of a single huge table.

Can we store blob in PostgreSQL?

Blob (Binary large object) is an Oracle data type that is used to store binary data like contents of a file or information like audio, video, and images. PostgreSQL does not have the Blob data type directly, but we can work with it using the methods below.


2 Answers

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

like image 64
Erwin Brandstetter Avatar answered Sep 19 '22 07:09

Erwin Brandstetter


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.

like image 29
Pavel Stehule Avatar answered Sep 21 '22 07:09

Pavel Stehule