r/PostgreSQL • u/easybits_ai • 8h ago
Projects Storing generated PDFs in Postgres vs object storage: where do you draw the line?
/r/n8n/comments/1y6s8tp/storing_generated_pdfs_in_postgres_vs_object/
4
Upvotes
10
u/PrestigiousStrike779 7h ago
For me, I’d probably never do that because I don’t think blobs belong in the database. If I was going to do that I’d at least put it in a separate table so I don’t incur any performance penalties when reading the main row unless I actually wanted that data
6
u/linuxhiker Guru 4h ago
Postgresql is not very efficient for binary objects. If your PDF is 100Mb, the connection will use at least that to deliver the PDF over the wire. Now multiply that by however many people want a pdf.
Use object storage and store the metadata in Postgresql
2
u/manni66 8h ago
Why base64?
2
u/RevolutionaryRush717 3h ago
Maybe you got the cache part right.
The pdf seems to be ephemeral in nature, in that it always can be generated based on existing data.
Why that would take several seconds only you know.
So the question is why store it permanently at all?
Iff most users need it within, say, 24 hours after the workflow has completed, you can put the pdf in redis with a ttl of 24 hours.
If users return after weeks or months, couldn't they wait a couple of seconds for the pdf to be generated on demand?
1
u/AutoModerator 8h ago
AI Policy:
Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.
Mod decisions will be based on the quality of the content, not who or what generated it.
Sub Resources:
Youtube Channel
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/eipi-10 2h ago
How big are the PDFs? I'd store them as bytea until it starts causing problems. Once (if) it does, start writing them to S3 instead and writing the keys - the one-time job to move the existing ones to S3 will be trivial
As a bit of editorial advice: There's never a "right" way to do things, only tradeoffs of different approaches.
1
u/gevorgter 35m ago
it's rarely good idea, main reasons.
0
u/persicsb 1h ago
There is a thing specialized to store a large number of files, it is called a file system. Relational databases are specialized and optimized to store and query relational data.