jackc / pglogrepl

PostgreSQL logical replication library for Go.
MIT License
330 stars 62 forks source link

Add support of v2 replication protocol #55

Closed alikonhz closed 1 year ago

alikonhz commented 1 year ago

Postgres since version 14 supports streaming large in-progress transactions via replication connection. This PR adds support of new messages (Stream Start/Stop/Commit/Abort) as well as updated V2 messages. Some messages (e.g. Insert/Update/Delete) have additional field (xid) when being streamed via V2 protocol. I addressed this by creating new structs *V2 (InsertMessageV2, etc.) and adding function ParseV2(data []byte, inStream bool). I also updated sample application. I took Information about message format from here: https://www.postgresql.org/docs/current/protocol-logicalrep-message-formats.html

jackc commented 1 year ago

At first glance it LGTM, but I haven't used the v2 streaming protocol, so I'd appreciate if we can get a few more reviewers.

alikonhz commented 1 year ago

Hi @jackc, Do you have someone on your mind in particular? I don't know anyone with experience in PG logical decoding. However, I may create integration test which will validate the protocol on an actual PG database.

jackc commented 1 year ago

@alikonhz I don't have anyone in particular in mind but there usually are a few people watching this repo. I'll give this a week or so and then merge it if no one gives any additional feedback.

diabloneo commented 1 year ago

My mainly experience is about V1 protocol, but I can read the spec firstly then review the code.

jackc commented 1 year ago

Thanks!