Skip to content

Accept InsertMessage with zero-column tuples - #86

Merged
jackc merged 1 commit into
jackc:masterfrom
PeerDB-io:fix-zero-column-insert
Oct 3, 2026
Merged

jackc merged 1 commit into
jackc:masterfrom
PeerDB-io:fix-zero-column-insert

Conversation

@ilidemi

@ilidemi ilidemi commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

PostgreSQL can have tables with no replicated columns: created that way initially, columns dropped later, or only generated columns. InsertMessage payload for those is 7 bytes long (4-byte relation ID, 'N', 2-byte column count of 0), but InsertMessage.Decode fails with InsertMessage must have 8 bytes, got 7 bytes.

This is an arguably questionable case to try and replicate, however there can be a situation where a publication is created for all tables, only a few are actually being consumed in CDC/replication downstream, then an unrelated table creation/modification breaks a running pipeline without a way to recover. UpdateMessage and DeleteMessage already support zero-column tuples.

InsertMessageV2 check had the same off-by-one (12 instead of 11), also fixed here. Added tests for both cases.

PostgreSQL emits zero-column tuples for inserts into tables with no
replicated columns: tables created with no columns, tables whose columns
have all been dropped, and (before PG 18) tables with only generated
columns. The payload is then 7 bytes (relation ID, 'N', column count 0),
but InsertMessage.Decode required at least 8, so decoding failed with
"InsertMessage must have 8 bytes, got 7 bytes" and a replication stream
could not progress past such a change. The in-stream InsertMessageV2
check had the same off-by-one (12 instead of 11).
@jackc
jackc merged commit 662581b into jackc:master Oct 3, 2026
12 checks passed
ilidemi added a commit to PeerDB-io/peerdb that referenced this pull request Oct 9, 2026
Include jackc/pglogrepl#86 to support
zero-column inserts
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