Add a hook for handling logical decoding messages on subscribers. - #415
Open
pg-hub-mirror[bot] wants to merge 1 commit into
Open
pg-hub-mirror[bot] wants to merge 1 commit into
pg-hub-mirror[bot] wants to merge 1 commit into
Conversation
Previously, pgoutput could emit logical decoding messages, those written with pg_logical_emit_message(), but the built-in subscriber never requested them from the publisher, and apply_handle_message() was only a placeholder that discarded the MESSAGE message type. Acting on such messages therefore meant writing a separate logical decoding client, and giving up the apply worker's streaming, conflict handling and progress tracking. Logical messages are a general-purpose side channel carried in band with the data, useful for replicating deparsed DDL, for carrying change-data-capture context that the row data does not have, and for cache invalidation delivered in commit order relative to the rows it refers to. This commit adds a new "messages" subscription option, which asks the publisher for the pgoutput "messages" option, and dispatches each received message to a new LogicalRepMessageHandle_hook. Behavior is unchanged when the option is off or when no handler is installed. A transactional message is applied as a step of the remote transaction it belongs to, so the handler's work commits atomically with that transaction, and transaction streaming and ALTER SUBSCRIPTION ... SKIP apply to it as they do to any other change. A non-transactional message belongs to no remote transaction and is committed on its own. A message may still reach the handler more than once, for example after an apply worker restart, so handlers must be idempotent. Note also that messages are not scoped by publication: every message emitted in the publisher database is sent, subject only to origin filtering, and pg_logical_emit_message() requires no special privileges. A handler must therefore treat the payload as untrusted input, and as an arbitrary string of bytes rather than as text in the subscriber's encoding. The publisher must be running PostgreSQL 14 or later, where pgoutput gained the "messages" option; against an older publisher the option is accepted but no message is ever sent. Bump catalog version. Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/CAD21AoCTNGiddikkUcDKj5QLnsg-51bpr-o6L-GTHWZL4ZFYtQ@mail.gmail.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pgsql-hackersCAD21AoDrvttNr0sOywJ7+1C1pivOgj8L3QuMqpziPDRopw+UDQ@mail.gmail.comPatch files:
On Thu, Aug 6, 2026 at 10:42 AM Bharath Rupireddy
<bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote: