Skip to content

Fix wal2mongo build failures against PostgreSQL 17, 18, and 19.#6

Open
devrimgunduz wants to merge 1 commit into
HighgoSoftware:releasefrom
devrimgunduz:release
Open

Fix wal2mongo build failures against PostgreSQL 17, 18, and 19.#6
devrimgunduz wants to merge 1 commit into
HighgoSoftware:releasefrom
devrimgunduz:release

Conversation

@devrimgunduz

@devrimgunduz devrimgunduz commented Jun 25, 2026

Copy link
Copy Markdown

PG 17 / 18:

  • change->data.tp.newtuple and oldtuple changed type from ReorderBufferTupleBuf * (requiring ->tuple dereference to obtain HeapTupleData) to bare HeapTuple. Drop the ->tuple member access and pass the pointer directly to tuple_to_stringinfo() for all five call sites (INSERT, UPDATE old/new/pkAttrs, DELETE).

PG 19:

  • RepOriginId renamed to ReplOriginId; InvalidRepOriginId renamed to InvalidReplOriginId. Update forward declaration, function definition, and the only_local guard accordingly.
  • AssertVariableIsOfType() removed; replace with StaticAssertVariableIsOfType() which performs the same check at compile time.
  • VARATT_IS_EXTERNAL_ONDISK(), VARSIZE_ANY_EXHDR(), and VARDATA_ANY() now take const void * instead of accepting Datum implicitly. Wrap the Datum arguments with DatumGetPointer() at the three affected call sites.

All versions:

  • Remove always-true (valptr+1) != NULL guard in print_w2m_literal(). Pointer arithmetic on a non-null pointer never yields NULL; the compiler correctly warns about this. The *(valptr+1) read is safe regardless: the loop iterates while *valptr != '\0', so valptr+1 is always within the string or pointing at the null terminator, neither of which requires a NULL check.

All changes are guarded with appropriate #if PG_VERSION_NUM >= NNNNNN blocks to preserve backwards compatibility with PG 13-16.

pgdg-packaging/pgdg-rpms#213

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with newer PostgreSQL versions.
    • Fixed handling of change decoding across different PostgreSQL releases, including insert, update, and delete events.
    • Adjusted string escaping and literal rendering for more reliable output.
    • Improved handling of on-disk and tuple data so decoded changes continue to render correctly across supported versions.

PG 17 / 18:
- change->data.tp.newtuple and oldtuple changed type from
  ReorderBufferTupleBuf * (requiring ->tuple dereference to obtain
  HeapTupleData) to bare HeapTuple. Drop the ->tuple member access
  and pass the pointer directly to tuple_to_stringinfo() for all five
  call sites (INSERT, UPDATE old/new/pkAttrs, DELETE).

PG 19:
- RepOriginId renamed to ReplOriginId; InvalidRepOriginId renamed to
  InvalidReplOriginId. Update forward declaration, function definition,
  and the only_local guard accordingly.
- AssertVariableIsOfType() removed; replace with
  StaticAssertVariableIsOfType() which performs the same check at
  compile time.
- VARATT_IS_EXTERNAL_ONDISK(), VARSIZE_ANY_EXHDR(), and VARDATA_ANY()
  now take const void * instead of accepting Datum implicitly. Wrap
  the Datum arguments with DatumGetPointer() at the three affected
  call sites.

All versions:
- Remove always-true (valptr+1) != NULL guard in print_w2m_literal().
  Pointer arithmetic on a non-null pointer never yields NULL; the
  compiler correctly warns about this. The *(valptr+1) read is safe
  regardless: the loop iterates while *valptr != '\0', so valptr+1
  is always within the string or pointing at the null terminator,
  neither of which requires a NULL check.

All changes are guarded with appropriate #if PG_VERSION_NUM >= NNNNNN
blocks to preserve backwards compatibility with PG 13-16.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6c660728-54e6-41dc-a5d1-c5c08711a2c7

📥 Commits

Reviewing files that changed from the base of the PR and between 0f47e67 and 41269f2.

📒 Files selected for processing (1)
  • wal2mongo.c

📝 Walkthrough

Walkthrough

wal2mongo.c adds PostgreSQL version guards for decoder initialization, origin filtering, literal/bytea rendering, and tuple access while formatting INSERT, UPDATE, and DELETE changes.

Changes

PostgreSQL version compatibility

Layer / File(s) Summary
Decoder init and filter checks
wal2mongo.c
pg_w2m_decode_filter and _PG_output_plugin_init use PostgreSQL-version-specific origin ID types and symbol type checks.
Literal and bytea rendering
wal2mongo.c
print_w2m_literal and tuple_to_stringinfo switch pointer and length handling for JSON escaping, toasted values, and bytea hex encoding across PostgreSQL versions.
Decoded change tuple access
wal2mongo.c
pg_w2m_decode_change selects different tuple access forms for INSERT, UPDATE, and DELETE rendering on PostgreSQL 17+ versus older releases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • PostgreSQL 18 support #5 — This PR updates PostgreSQL version compatibility in wal2mongo.c, including the tuple access changes on newer PostgreSQL versions.

Poem

🐇 Hop, hop! I thump through version gates so bright,
Old tuples and new tuples dance just right.
Bytea crumbs sparkle, JSON shells gleam,
In wal2mongo burrows, the code keeps its beam.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: PostgreSQL 17-19 compatibility fixes for wal2mongo build failures.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant