Skip to content

Commit b99e2bb

Browse files
committed
Document max read and write sizes for large objects
#1865
1 parent 52f2151 commit b99e2bb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

large_objects.go

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ type LargeObject struct {
6767
}
6868

6969
// Write writes p to the large object and returns the number of bytes written and an error if not all of p was written.
70+
//
71+
// Write is implemented with a single call to lowrite. The PostgreSQL wire protocol has a limit of 1 GB - 1 per message.
72+
// See definition of PQ_LARGE_MESSAGE_LIMIT in the PostgreSQL source code. To allow for the other data in the message,
73+
// len(p) should be no larger than 1 GB - 1 KB.
7074
func (o *LargeObject) Write(p []byte) (int, error) {
7175
var n int
7276
err := o.tx.QueryRow(o.ctx, "select lowrite($1, $2)", o.fd, p).Scan(&n)
@@ -82,6 +86,10 @@ func (o *LargeObject) Write(p []byte) (int, error) {
8286
}
8387

8488
// Read reads up to len(p) bytes into p returning the number of bytes read.
89+
//
90+
// Read is implemented with a single call to loread. PostgreSQL internally allocates a single buffer for the response.
91+
// The largest buffer PostgreSQL will allocate is 1 GB - 1. See definition of MaxAllocSize in the PostgreSQL source
92+
// code. To allow for the other data in the message, len(p) should be no larger than 1 GB - 1 KB.
8593
func (o *LargeObject) Read(p []byte) (int, error) {
8694
var res []byte
8795
err := o.tx.QueryRow(o.ctx, "select loread($1, $2)", o.fd, len(p)).Scan(&res)

0 commit comments

Comments
 (0)