Skip to content

Support streaming COPY FROM STDIN and COPY TO STDOUT - #1696

Open
doxlik wants to merge 1 commit into
eclipse-vertx:masterfrom
doxlik:pg-copy
Open

Support streaming COPY FROM STDIN and COPY TO STDOUT#1696
doxlik wants to merge 1 commit into
eclipse-vertx:masterfrom
doxlik:pg-copy

Conversation

@doxlik

@doxlik doxlik commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Expose the PostgreSQL COPY subprotocol on PgConnection as raw byte streams, so bulk data transfers no longer have to be materialized in memory.

copyOut(String) executes a COPY ... TO STDOUT statement and returns a PgCopyOut, a ReadStream of Buffer whose completion() carries the row count reported by the server. Each CopyData message is emitted as one buffer by default; PgCopyOutOptions.setAggregationThreshold(int) coalesces small messages when throughput matters more than message boundaries.

copyIn(String) executes a COPY ... FROM STDIN statement and returns a PgCopyIn, a WriteStream of Buffer honouring writeQueueFull() and drainHandler(). Small writes are batched up to PgCopyInOptions chunkSize, and abort(String) sends CopyFail so the server rolls the copy back.

The outcome of a COPY is always the one PostgreSQL reports, never synthesised by the client: completion() resolves at ReadyForQuery, which is also what leaves the connection usable for the next statement.

Resolves #153

@doxlik

doxlik commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

@vietj @tsegismont hi. Please have a look once you have time.

Expose the PostgreSQL COPY subprotocol on PgConnection as raw byte
streams, so bulk data transfers no longer have to be materialized in
memory.

copyOut(String) executes a COPY ... TO STDOUT statement and returns a
PgCopyOut, a ReadStream of Buffer whose completion() carries the row
count reported by the server. Each CopyData message is emitted as one
buffer by default; PgCopyOutOptions.setAggregationThreshold(int)
coalesces small messages when throughput matters more than message
boundaries.

copyIn(String) executes a COPY ... FROM STDIN statement and returns a
PgCopyIn, a WriteStream of Buffer honouring writeQueueFull() and
drainHandler(). Small writes are batched up to PgCopyInOptions
chunkSize, and abort(String) sends CopyFail so the server rolls the
copy back.

The outcome of a COPY is always the one PostgreSQL reports, never
synthesised by the client: completion() resolves at ReadyForQuery, which
is also what leaves the connection usable for the next statement.

Signed-off-by: doxlik <doxlikx@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COPY command

1 participant