News for hackers. Stuff that matters.
Re:File Attachments: Databases can now store files and images by adrianmsmith on Wednesday August 30, 2023 @01:12PM (#37325379)
I think for smaller projects just storing images as BLOBs in e.g. PostgreSQL works quite well.

I know this is controversial. People will claim it's bad for performance.

But that's only bad if performance is something you're having problems with, or going to have problems with. If the system you're working on is small, and going to stay small, then that doesn't matter. Not all systems are like this, but some are.

Storing the images directly in the database has a lot of advantages. They share a transactional context with the other updates you're doing. They get backed up at the same time, and if you do a "point in time" restore they're consistent with the rest of your data. No additional infrastructure to manage to store the files.

Re:File Attachments: Databases can now store files and images by doubled112 on Wednesday August 30, 2023 @01:38PM (#37325841)
I've seen BLOBs in an Oracle DB used to store Oracle install ISOs, which I think is ironic on some level.

Let's attach what we're using to the ticket. All of it. Why is the ticketing DB huge? Well, you attached all of it.

Re:File Attachments: Databases can now store files and images by richbell on Wednesday August 30, 2023 @07:56PM (#37330732)
I once helped migrate data from a 3+ TB Oracle database for a ticketing system. It was supposed to be shut down more than a year prior but the task kept getting passed around like a hot potato.

I can't imagine how much money we were paying in licensing fees and storage costs.

Re:File Attachments: Databases can now store files and images by mohamedattahri on Wednesday August 30, 2023 @01:25PM (#37325611)
BLOB on Postgres are awesome, but there's also a full-featured file API called Large Objects for when the use-case requires seeking/streaming.

Wrote a small Go library to interface with it: https://github.com/mohamedattahri/pgfs

Large Objects: https://www.postgresql.org/docs/current/largeobjects.html

Re:File Attachments: Databases can now store files and images by dventimi on Wednesday August 30, 2023 @02:04PM (#37326284)
Large Objects works great for images and stylesheets and other file assets for my small PostgREST projects.
Re:File Attachments: Databases can now store files and images by ibgeek on Wednesday August 30, 2023 @04:15PM (#37328352)
TIL thanks!
Re:File Attachments: Databases can now store files and images by andyp-kw on Wednesday August 30, 2023 @01:23PM (#37325572)
I've seen companies store pdf invoices in the database too, for the same reasons you spoke of.
Re:File Attachments: Databases can now store files and images by ltbarcly3 on Wednesday August 30, 2023 @01:51PM (#37326058)
I think there is too much emphasis on 'the right way' sometimes, which leads people to skip over an analysis for the problem they are solving right now.

For example, if you are building something that will have thousands or millions of records, and storing small binaries in postgresql lets you avoid integrating with S3 at all, then you should seriously consider doing it. The simplification gain almost certainly pays for any 'badness' and then some.

If you are working on something that you hope to scale to millions of users then you should just bite the bullet and integrate with S3 or something, because you will use too much db capacity to store binaries (assuming they aren't like 50 bytes each or something remarkably small) and that will force you to scale-out the database far before you would otherwise be forced to do so.

Re:File Attachments: Databases can now store files and images by crooked-v on Wednesday August 30, 2023 @02:12PM (#37326427)
> and that will force you to scale-out the database far before you would otherwise be forced to do so

Disk space is cheap, even when it's on a DB server and not S3. Why worry that much about it?

Re:File Attachments: Databases can now store files and images by tomnipotent on Wednesday August 30, 2023 @02:26PM (#37326656)
> Disk space is cheap

Disk I/O less so. An average RDBMS writing a 10MB BLOB is actually writing at minimum 20-30MB to disk - once to journal/WAL, once to table storage, and for updates/deletes a third copy in the redo/undo log.

You also get a less efficient buffer manager with a higher eviction rate, which can further exasperate disk I/O.

Re:File Attachments: Databases can now store files and images by crooked-v on Wednesday August 30, 2023 @02:32PM (#37326735)
But if the files are important enough that you need transactional updates or point-in-time recovery for them, you're stuck with the equivalents of those things anyway, wherever those files end up, plus the extra overhead of coordinating two systems.
Re:File Attachments: Databases can now store files and images by ltbarcly3 on Thursday August 31, 2023 @07:50AM (#37335746)
But there is a hard limit to db scale up and you don't want to hit it. Also, who said you need transactional updates or pit recovery in all cases?
Re:File Attachments: Databases can now store files and images by ransom1538 on Wednesday August 30, 2023 @03:40PM (#37327843)
Disk space is cheap. Slap on a db, now you got cpu, memory + an entire db OS inside an OS. Now its an expensive mess.
Re:File Attachments: Databases can now store files and images by sorintm on Wednesday August 30, 2023 @02:55PM (#37327112)
Brilliant point! It always depends on the problem you're trying to solve. What Xata did, was integrate files as a database column, BUT stored the binary content in S3. Thus offering both transactional file management and point in time recovery as well as high performance direct (S3) file access, through a CDN. Basically Xata implements the orchestration and takes away the pain of managing 2 services.
Re:File Attachments: Databases can now store files and images by ltbarcly3 on Thursday August 31, 2023 @07:52AM (#37335762)
The last thing I would do is use a proprietary solution from a startup to store data. Sorry, but that is just absolutely insane.
Re:File Attachments: Databases can now store files and images by harshitaneja on Wednesday August 30, 2023 @05:36PM (#37329458)
Going on a tangent here but why s3? Why not avoid vendor lock in and just serve static files?

My setup is to post blobs over a small rest api which balances storage load over all the file servers using nginx. It responds with the serverSubdomainId which in turn gets saved in the database. So the url for file access can be generated https://{serverSubdomainId}.domain.tld/{resourceId} The only costly part is writing which with caching of available storage of all the servers isn’t bad. The whole system is horizontally and vertically scalable. What am I missing that s3 is still the defacto even with vendor lock in and high egress costs?

Re:File Attachments: Databases can now store files and images by aforwardslash on Wednesday August 30, 2023 @06:18PM (#37329899)
There are plenty of oss solutions that talk "s3", like swift, ceph and seaweedfs.

Why object storage? Its easier to backup, version and to scale horizontally. Most solutions will also provide encryption capabilities that can be commanded either via external key management systems or from the client application. Also, custom access policies are great for private documents and file uploads.

Using static files is a good solution in some cases, nothing against it. But in many scenarios, there are huge benefits on using object storage instead, even if it is quite slower.

Re:File Attachments: Databases can now store files and images by timando on Wednesday August 30, 2023 @06:41PM (#37330094)
"S3" is often used to refer to any S3 compatible object storage system. You can even self-host it with something like MinIO.
Re:File Attachments: Databases can now store files and images by connordoner on Wednesday August 30, 2023 @07:00PM (#37330243)
I can't speak for everyone but, in my case, it comes down to the ease of setup and having someone else manage it.
Re:File Attachments: Databases can now store files and images by fiedzia on Wednesday August 30, 2023 @02:21PM (#37326577)
> If the system you're working on is small, and going to stay small, then that doesn't matter.

Having good default solution saves a lot of problems with migration. Storing files outside of database today really isn't that more complicated, while benefits even for small files are significant: you can use CDN, you don't want traffic spikes to affect database performance, you will want different availability guarantees for your media than for database and so on.

Re:File Attachments: Databases can now store files and images by EvanAnderson on Wednesday August 30, 2023 @02:39PM (#37326842)
The issue I've run into re: storing files as BLOBs in a database has been the "impedance mismatch" coming from others wanting to use tools that act on filesystem objects against the files stored in the database.

That aside I've had good experiences for some applications. It's certainly a lot easier than keeping a filesystem hierarchy in sync w/ the database, particularly if you're trying to replicate the database's native access control semantics to the filesystem. (So many applications get this wrong and leave their entire BLOB store, sitting out on a filesystem, completely exposed to filesystem-level actors with excessive permission.)

Microsoft has an interesting feature in SQL Server to expose BLOBs in a FUSE-like manner: https://learn.microsoft.com/en-us/sql/relational-databases/b...

I see postgresqlfs[0] on Github, but it's unclear exactly what it does and it looks like it has been idle for at least 6 years.

[0] https://github.com/petere/postgresqlfs

Re:File Attachments: Databases can now store files and images by harlanji on Wednesday August 30, 2023 @06:31PM (#37330013)
Minio is easy enough to spin up, S3-compatible. That seems like my default path to persistence going forward. More and more deployments options seem like they'll benefit from not using the disk directly but instead using the dedicated storage service path, so might as well use a tool designed for that.

S3 can be a bit of a mismatch for people who want to work with FS objects as well, but there are a couple options that are a lot easier than dealing with blob files in PGsql. S3cmd, S3fs; perhaps SSHfs to the backing directory of Minio or direct access on the host (direct routes untested, unsure if it maps 1:1).

Re:File Attachments: Databases can now store files and images by SigmundA on Wednesday August 30, 2023 @03:04PM (#37327274)
Main issues with large blobs in DB is moving and or deleting them. Not sure if PG has this issue I would like to confirm, but in say SQL server if you delete a blob or try and move it to another file group you get transaction logging equal to the size of the blobs.

You would think at least with a delete especially in PG with the way it handles MVCC the blob would just have an entry saying which blob was deleted or something then if you need rollback you just undelete the blob.

So just being able to move and delete the data after it is in there becomes a real problem with a lot of it.

Re:File Attachments: Databases can now store files and images by vbezhenar on Wednesday August 30, 2023 @03:05PM (#37327296)
It makes backups PITA. I migrated blobs to S3 and managed to improve backups from once a month to once a day. Database is now very slim. HDD space is no longer an issue. Can delete code which serves files. Lots of improvements with no downsides so far.
Re:File Attachments: Databases can now store files and images by crooked-v on Wednesday August 30, 2023 @03:57PM (#37328094)
Of course, that also means that now you don't have backups of your files.
Re:File Attachments: Databases can now store files and images by 0x457 on Wednesday August 30, 2023 @04:05PM (#37328204)
They do have backups if versioning is enabled on S3.
Re:File Attachments: Databases can now store files and images by ericbarrett on Wednesday August 30, 2023 @04:32PM (#37328613)
Yes, S3 is extremely reliable and versioning protects against “oopsies.” I do always recommend disallowing s3:DeleteObjectVersion for all IAM roles, and/or as a bucket policy; manage old versions twith a lifecycle policy instead. This will protect against programmatic deletion by anybody except the root account.
Re:File Attachments: Databases can now store files and images by brazzledazzle on Wednesday August 30, 2023 @06:47PM (#37330155)
I second these sensible protections. Also would recommend replicating your bucket as a DR measure. Ideally to another (infrequently used and separately secured) account. Even better if you do it to another region but I think another account is more important since the chances of your account getting owned is higher than amazon suffering a total region failure.
Re:File Attachments: Databases can now store files and images by lovasoa on Wednesday August 30, 2023 @03:27PM (#37327622)
How big does the database need to be for large BLOBs to become a problem ? "big" and "small" are quite subjective terms.

How many BLOBs does one need to have, and how often to we need to touch them for this solution to become untenable ?

Re:File Attachments: Databases can now store files and images by crabbone on Wednesday August 30, 2023 @03:48PM (#37327939)
In storage you measure things in blocks. Historically, blocks were meant to be 512 bytes big, but today the tendency is to make them bigger, 4K would be the typical size in server setting.

So, the idea here is this: databases that store structured information, i.e. such that needs to store integers, booleans, short strings are typically something like relational databases, eg. PostgreSQL.

Filesystems (eg. Ext4) usually think about whole blocks, but are designed with the eye for smaller files, i.e. files aren't expected to be more than some ten or hundred blocks in size for optimal performance.

Object stores (eg. S3) are the kinds of storage systems that are supposed to work well for anything larger than typical files.

This gives the answer to your question: blobs in a relational database are probably OK if they are under one block big. Databases will be probably able to handle bigger ones too, but you will start seeing serious drops in performance when it comes to indexing, filtering, searching etc. because such systems optimize internal memory buffers in such a way that they can fit a "perfect" number of elements of the "perfect" size.

Another concern here is that with stored elements larger than single block you need a different approach to parallelism. Ultimately, the number of blocks used by an I/O operation determines its performance. If you are reading/writing sub-block sized elements, you try to make it so that they come from the same block to minimize the number of requests made to the physical storage. If you work with multi-block elements, your approach to performance optimization is different -- you try to pre-fetch the "neighbor" blocks because you expect you might need them soon. Modern storage hardware has a decent degree of parallelism that allows you to queue multiple I/O requests w/o awaiting completion. This later mechanism is a lot less relevant to something like RDBMS, but is at the heart of an object store.

In other words: the problem is not the function of the size of the database. In principle, nothing stops eg. PostgreSQL from special-casing blobs and dealing with them differently than it would normally do with "small" objects... but they aren't probably interested in doing so because you already have appropriate storage for that kind of stuff, and PostgreSQL, like most other RDBMS sits on top of the storage for larger objects (filesystem), so they have no hopes of doing it better than the layer below them.

Re:File Attachments: Databases can now store files and images by brazzy on Wednesday August 30, 2023 @04:45PM (#37328837)
Most of what you wrote there is simply not true for modern DBMS, specifically PostgreSQL has a mechanism called TOAST (https://www.enterprisedb.com/postgres-tutorials/postgresql-t...) that does exactly what you claim "they aren't probably interested in doing" and completely eliminates any performance penalty of large objects in a table when they are not used.
Re:File Attachments: Databases can now store files and images by crabbone on Thursday August 31, 2023 @09:14AM (#37336665)
sigh... lol, an "expert".

PostgreSQL just like most RDBMS uses filesystem as a backend. It cannot be faster than the filesystem it uses to store its data. At best, you may be able to configure it to use more caching, and then it will be "faster" when you have enough memory for caching...

Re:File Attachments: Databases can now store files and images by brazzy on Thursday August 31, 2023 @02:03PM (#37341302)
What does that have to do with my comment? I didn't say say that an RDBMS is faster than a filesystem, just that your statements about them "seeing serious drops in performance when it comes to indexing, filtering, searching etc." are clearly wrong.

It seems very clear that it is you who knows some vaguely relevant bit of trivia, but actually have no clue about the subject in general, and try to make up for that in arrogance. Which is, honestly, pretty embarrassing.

Re:File Attachments: Databases can now store files and images by TristanBall on Wednesday August 30, 2023 @07:43PM (#37330604)
"Filesystems (eg. Ext4) usually think about whole blocks, but are designed with the eye for smaller files, i.e. files aren't expected to be more than some ten or hundred blocks in size for optimal performance."

Sorry what?

I mean, ext4, as a special case, has some performance issues around multiple writers to a singe file when doing direct io, but I can't think of a single other place where your statement true... and plenty where it's just not ( xfs, jfs, zfs, ntfs, refs )

Re:File Attachments: Databases can now store files and images by crabbone on Thursday August 31, 2023 @09:30AM (#37336871)
God, how do you come up with this nonsense? Can you read what you reply to, or do you just write this to show off because you happened to know some vaguely relevant bit of trivia, but actually have no clue about the subject in general?

Yes, the goal of filesystem is to perform best when files are greater than one block and smaller than some couple hundreds of blocks. This is what it's optimized for. Can it deal with smaller or bigger files? -- Yes, but this is beside the point. Filesystem by design are meant for the sizes I mentioned. It's stupid to store information in files much smaller than single block because filesystems store a lot of file metadata per file. If your files are too small, then you start paying exorbitant price for metadata (filesystem don't optimize for storing metadata in bulk for multiple files because such optimization would mean a lot of synchronization when dealing with multiple files in parallel).

Similarly, filesystems, by and large aren't good for dealing with large chunks of data, like, eg. database backups, VM images etc. Typically, a storage system for large objects will try to optimize its performance by larger-than-block compression and deduplication. Neither makes sense when your target chunk size is in single to double digits of blocks -- there won't be enough overlap between different data chunks and you will pay more for decompression of data that you don't want to read, if the granularity of compressed chunks is too big.

And this is not a secret at all... talk to anyone who works on either database or filesystem or object store -- they will tell you exactly this. (I worked on a filesystem, for the record.) This is why these things all co-exist and are filling their respective niches...

Re:File Attachments: Databases can now store files and images by lovasoa on Friday September 01, 2023 @05:04PM (#37356161)
Wow, this comment is very rude and completely out of place.
Re:File Attachments: Databases can now store files and images by spiffytech on Wednesday August 30, 2023 @04:51PM (#37328916)
One datapoint on BLOB performance: SQLite: 35% Faster Than The Filesystem

https://www.sqlite.org/fasterthanfs.html

Re:File Attachments: Databases can now store files and images by hot_gril on Thursday August 31, 2023 @02:36AM (#37333285)
The Postgres TEXT type is limited to 65,535 bytes, to give a concrete number. "Big" usually means, big enough that you have to stream rather than sending all at once.
Re:File Attachments: Databases can now store files and images by asjo on Thursday August 31, 2023 @03:39PM (#37342643)
The PostgreSQL manual states:

> the longest possible character string that can be stored is about 1 GB.

· https://www.postgresql.org/docs/current/datatype-character.h...

See also: https://www.postgresql.org/docs/current/limits.html

Where do you have the 64KB number from?

A small test:

    test=# create table test_table (test_field text);
    CREATE TABLE
    test=# insert into test_table select string_agg('x', '') from generate_series(1, 128*1024);
    INSERT 0 1
    test=# select length(test_field) from test_table;
     length 
    --------
     131072
    (1 row)
Re:File Attachments: Databases can now store files and images by hot_gril on Thursday August 31, 2023 @03:46PM (#37342729)
You're right. Bad Google suggestion for "max string length postgres" that pointed to https://hevodata.com/learn/postgresql-varchar/ saying varchar max is 64KB, which is also wrong. I gotta stick to the official docs. Anyway, TEXT is the one we care about.

In MySQL, the TEXT (and BLOB) limit is 65KB, but you can get 4GB using LONGTEXT. According to their docs: https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.h...

Re:File Attachments: Databases can now store files and images by ransom1538 on Wednesday August 30, 2023 @03:38PM (#37327812)
Fat tables. A great way to destroy your database future. If you are planing on going to nosql this is a great way to convince the team to move. "Look our backups don't even work!"
Re:File Attachments: Databases can now store files and images by rajman187 on Wednesday August 30, 2023 @04:51PM (#37328931)
Several years ago Walmart dramatically sped up their online store's performance by storing images as blobs in their distributed Cassandra cluster.

https://medium.com/walmartglobaltech/building-object-store-s...

Re:File Attachments: Databases can now store files and images by bastawhiz on Wednesday August 30, 2023 @05:12PM (#37329220)
I think the one big problem with BLOBs, especially if you have a heavily read-biased DB, is you're going to run up against bandwidth/throughput as a bottleneck. One of the DBs I help maintain has some very large JSON columns and we frequently see this problem when traffic is at its peak: simply pulling the data down from Postgres is the problem.

If the data is frequently accessed, it also means there are extra hops the data has to take before getting to the user. It's a lot faster to pull static files from S3 or a CDN (or even just a dumb static file server) than it is to round trip through your application to the DB and back. For one, it's almost impossible to stream the response, so the whole BLOB needs to be copied in memory in each system it passes through.

It's rare that any request for, say, user data would also return the user avatar, and so you ultimately just end up with one endpoint for structured data and one to serve binary BLOB data which have very little overlap except for ACL stuff, but signed S3 URLs will get you the same security properties with much better performance overall.

Re:File Attachments: Databases can now store files and images by refulgentis on Wednesday August 30, 2023 @06:38PM (#37330076)
Do you have any thoughts on when a JSON column is too large? I've been wondering about the tradeoffs between a jsonb column in postgres that may have values, at the extreme, as large as 10 MB, usually just 100 KB, versus using S3.
Re:File Attachments: Databases can now store files and images by xmprt on Wednesday August 30, 2023 @10:54PM (#37331918)
Wouldn't the same reasoning for BLOBs apply to JSON columns? Unless you're frequently querying for data within those columns (eg, filtering by one of the JSON fields), then you probably don't need to store all the JSON data in the DB. And even if that is the case, you could probably work out a schema where the JSON data is stored elsewhere and only the relevant fields are stored in the DB.

At the same time, I'm working with systems where we often store MBs of data in JSON columns and it's working fine so it's really up to you to make the tradeoff.

Re:File Attachments: Databases can now store files and images by bastawhiz on Saturday September 02, 2023 @04:04PM (#37365026)
If you're only querying the JSON data and not returning it in full often, it's almost certainly fine. It's the cost of transit (and parsing/serialization) that's a problem.
Re:File Attachments: Databases can now store files and images by bastawhiz on Saturday September 02, 2023 @04:03PM (#37365014)
It depends on how much you're getting back total. 100 rows returning a kb of data is the same as one row with 100kb. I get worried when the total expected data returned by a query is more than 200kb or so.
Re:File Attachments: Databases can now store files and images by avereveard on Wednesday August 30, 2023 @07:11PM (#37330333)
Also cost is a factor, databases are usually attached to expensive disk and their storage layer is tuned for iops, and blobs will be using gigs of that for just sitting there being sequentially scanned.
Re:File Attachments: Databases can now store files and images by sroussey on Wednesday August 30, 2023 @07:28PM (#37330464)
Ignoring ACL stuff for the moment, if you put images for a user's blog post inside a database, then front it with a CDN, thing might work out fine.

But if the usage pattern was such that the blog post and images were being transformed based on the time or something, then nothing would get cached, and back to the issue you describe.

That said... you could setup read replicas into groups and direct the blob stuff to a pool that is separate from the higher priority data requests for normal db stuff.

Re:File Attachments: Databases can now store files and images by SOLAR_FIELDS on Wednesday August 30, 2023 @07:43PM (#37330602)
I have to worked with BLOBs in DB fields in almost a decade, but when I worked with them one really annoying problem I ran into was that the DB wanted to morph the blob in transit by default. So JPEGs and PDFs etc would get corrupted because SQL Server wanted to add its own little byte signature to it during read/write operations.

Not sure if that was an endemic problem or a specific SQL server shiftiness

Re:File Attachments: Databases can now store files and images by fovc on Wednesday August 30, 2023 @10:37PM (#37331826)
We had this problem as well. For us a big part of the latency was just the bandwidth required for Postgres’s verbose text mode. It’s a shame there’s no way to compress the data on the wire
Re:File Attachments: Databases can now store files and images by commonlisp94 on Wednesday August 30, 2023 @10:41PM (#37331844)
You can cache them on disk. The DB blob is just the source of truth.
Re:File Attachments: Databases can now store files and images by throwaway2990 on Thursday August 31, 2023 @01:04AM (#37332674)
Using PostgreSQL as a document database so everything is stored as JSONB and it’s only around 800gb but it’s still lightning fast.
Re:File Attachments: Databases can now store files and images by dfee on Thursday August 31, 2023 @01:04AM (#37332676)
I’m sure you’re right, but it’s unbelievable to me how cost effective people claim S3 is. I’ve just never been able to get the pricing calculator to show me “cheap”. And I guess I’ve never really gotten comfortable with the access patterns, as it’s not a file system.

Where could I explore situations where people have used S3 with extremely favorable conditions relative to local storage(?), in terms of: price, access latency, and any other relevant column?

I want to believe, it’s just hard for me to go all in on an Amazon API.

Re:File Attachments: Databases can now store files and images by rrrix1 on Thursday August 31, 2023 @01:26AM (#37332805)
> relative to local storage

That's the catch. S3 is ideal for when the sum total of your blobs can't easily fit on local storage - unless you want to use a NAS, SAN or something else with a load of spinning rust.

Storing your data on a single HDD you got off NewEgg will always win if you only use the one metric of $/GB.

S3's main draw isn't $/GB. It's actually more like ($/GB) * features

E.g. 12-9s of durability, Lambda events, bucket policies, object tags, object versioning, object lock, cross region replication

Doing that with anything over 100TB starts to get very expensive very quickly. Especially if you need that data for, you know, your business to survive...

Re:File Attachments: Databases can now store files and images by rewmie on Thursday August 31, 2023 @03:26AM (#37333649)
> Storing your data on a single HDD you got off NewEgg will always win if you only use the one metric of $/GB.

That right there is the mistake you're making. Storage is not the only way that AWS charges you for S3. You're also billed for stuff like each HTTP request, each metadata tag, and data transferred out once you drop off the free tier. You're basically charged for every time you look at data you put in a S3 bucket the wrong way.

I strongly recommend you look at S3's pricing. You might argue that you feel S3 is convenient, but you pay through the nose for it.

https://aws.amazon.com/s3/pricing/

Re:File Attachments: Databases can now store files and images by dfee on Thursday August 31, 2023 @12:11PM (#37339496)
The pricing calculator has given me the perspective you've shared, not the one of your comment's parent. It looks outrageously expensive.

Cloudflare's R2 pricing seems a lot more competitive, but it's still lock in: https://r2-calculator.cloudflare.com

Another pain is the testing story. I just want to be able to write to a FS. There are S3 fuse bindings, though. Maybe I'm just a dinsosaure these days.

Re:File Attachments: Databases can now store files and images by bastawhiz on Saturday September 02, 2023 @04:00PM (#37364998)
Well in fairness, if you're comparing Postgres to S3, there's no universe where S3 doesn't win on every way of pricing things out (unless you're only ever using the data from the same machine running Postgres perhaps).
Re:File Attachments: Databases can now store files and images by cryptonector on Wednesday August 30, 2023 @06:37PM (#37330062)
> But that's only bad if performance is something you're having problems with, or going to have problems with.

The first part is easy enough, but how do you predict when you're going to hit a knee in the system's performance?

Re:File Attachments: Databases can now store files and images by davedx on Thursday August 31, 2023 @01:49AM (#37332947)
We ran into issues doing this straightaway, because you also need to fetch the file out of the database in your application server, then send it to clients through the load balancer. That introduces bottlenecks.

Generally I agree don't prematurely optimize. But for us, not even having huge files (5-25 MB on average), it slowed our application down unacceptably storing file data in the database, and we ended up moving file data to S3 with a streaming API in front of it.

Re:File Attachments: Databases can now store files and images by hot_gril on Thursday August 31, 2023 @02:30AM (#37333252)
I'm on board with using temporary solutions for small projects, but I feel like BLOB isn't super convenient either unless you have some particular reason you only want Postgres as a dependency. I can either set up something like S3 where I upload via some simple API and get URLs to send back to clients, or I can build an image serving HTTP handler that queries the DB. The BLOB way is a little more manual if anything.

Similar story with caches. Sometimes I've used Postgres as a cache, but writing the little logic for that is already more hassle than just plopping in memcached or Redis and using a basic client.

Re:File Attachments: Databases can now store files and images by plasticeagle on Thursday August 31, 2023 @02:47AM (#37333357)
I would absolutely agree with this, were it not for the fact that your table appears to grow without bound - and is very very hard to clean up.

I know this, because this is exactly what I did. Put the images and the logfiles from an automated test suite directly into the DB. Brilliant, I thought! No more tracking separate files, performance was great, everything was rosy.

And then I tried to prune some old data.