-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Postgres] Streaming from/to BYTEA column type #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The problem with streaming requests/responses with Postgres is that it explicitly recommends to fully buffer messages before sending them or processing them (Messaging Overview section):
Because messages require a byte-length header, we would need to know the exact size of the stream we're reading into Postgres, and more importantly be able to trust that size. I'm all for discussing solutions here, but honestly if your files are too big to buffer in memory then you might consider storing them outside of Postgres; it's not meant for extremely large blobs. |
I know you mention you can't use binary large objects, but do you mind if you share context? They're explicitly designed for exactly this, streaming huge amounts of data to a single column. |
The Large-Object interface would actually be pretty neat to implement as an async interface. It's required in a transaction so it could be an |
While discussing a new project with a colleague of mine, he affirmed that large-object in Postgres should be avoided if possible. Some of his arguments are that:
I am not a db manager and I am trying to clarify what is real about those claims and if there is an alternative path. Having read in the doc that sqlx offers "Row streaming. Data is read asynchronously from the database and decoded on-demand.", I wanted to check whether it could help me streaming from/to BYTEA columns. |
Streaming output is done on a row-by-row basis since they arrive in self-contained packets. Anything more granular than that (e.g. for individual columns) would require a significant refactor of the Postgres driver. Streaming input would, on top of also being a significant refactor, also be very hazard-prone because if the source stream is fallible the only way to recover from an error is to close the connection; the normal Postgres binary protocol has no provision for canceling incomplete messages. However, the protocol in This has its own challenges though, which we've been discussing in #36 |
Even for |
Closing as this isn't directly possible. |
Is it possible to insert into and read from a BYTEA column without fetching the entire binary data in memory?
For example, I have this table:
I would like to:
Is there a way to achieve it?
Would my issue be solved by #36 ?
Please note that I cannot use Postgres Large Objects.
The text was updated successfully, but these errors were encountered: