Skip to content

fix: copy-in transaction status and Sync handling - #466

Merged
sunng87 merged 2 commits into
sunng87:masterfrom
altertable-ai:altertable/v0.38.3
Sep 29, 2026
Merged

sunng87 merged 2 commits into
sunng87:masterfrom
altertable-ai:altertable/v0.38.3

Conversation

@redox

@redox redox commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Two fixes to the copy-in sub-protocol, both found running pgwire behind an ETL tool that loads data with BEGIN; COPY ... FROM STDIN; COMMIT.

1. Report the tracked transaction status after a simple-protocol COPY

When a COPY ... FROM STDIN started from a simple Query completes, the server always answers ReadyForQuery(Idle), regardless of the connection's transaction state.

The transaction is still open on the server, but clients that track the transaction state from ReadyForQuery (libpq's PQtransactionStatus, pgjdbc, ...) now believe it has ended.

2. Ignore Flush and Sync during copy-in, like PostgreSQL

Since #465 (unreleased), a Sync received during copy-in aborts the copy with 08P01. rust-postgres (tokio-postgres) pipelines Bind, Execute, Sync before sending any CopyData, so every extended-protocol COPY FROM STDIN from it now fails with "unexpected message type during COPY".

PostgreSQL ignores these messages. From the protocol docs:

The backend will ignore Flush and Sync messages received during copy-in mode. Receipt of any other non-copy message type constitutes an error that will abort the copy-in state as described above. (The exception for Flush and Sync is for the convenience of client libraries that always send Flush or Sync after an Execute message, without checking whether the command to be executed is a COPY FROM STDIN.)

The CopyInProgress state now ignores Flush and Sync; any other non-copy message still aborts the copy. The terminating Sync after CopyDone is still routed to on_sync as introduced in #465.

… FROM STDIN

A successful simple-protocol CopyDone always answered ReadyForQuery(Idle),
so a COPY run inside BEGIN made clients that track the transaction state
from ReadyForQuery believe the transaction had ended.

Co-authored-by: Cursor <cursoragent@cursor.com>
@redox
redox force-pushed the altertable/v0.38.3 branch from 5818284 to f3c63fa Compare September 28, 2026 15:19
rust-postgres pipelines a Sync right after the Execute that starts a
COPY FROM STDIN, before any CopyData. Since sunng87#465 that Sync aborted the
copy with 08P01, breaking every extended-protocol copy from that client.
PostgreSQL ignores Flush and Sync in copy-in mode for exactly this reason.

Co-authored-by: Cursor <cursoragent@cursor.com>
@redox redox changed the title Report the real transaction status after COPY FROM STDIN fix: copy-in transaction status and Sync handling Sep 28, 2026

@sunng87 sunng87 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @redox . Confirmed this behavior aligns with original postgres

@sunng87
sunng87 merged commit 4031e6a into sunng87:master Sep 29, 2026
11 checks passed
@redox

redox commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @redox . Confirmed this behavior aligns with original postgres

Amazing to read! Looking forward to next release 🚀

@sunng87

sunng87 commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Just pushed a patch release with this. Thank you!
It would be nice if you can share about your use case with pgwire.

@redox

redox commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Just pushed a patch release with this. Thank you!
It would be nice if you can share about your use case with pgwire.

Absolutely! Trying to make Fivetran work with https://altertable.ai/ and the postgres adapter in front of our lakehouse (until we have a proper destination in Fivetran).

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.

2 participants