Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wc5SD-0034rK-1C for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jun 2026 18:02:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wc5SC-00D7iw-0k for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jun 2026 18:02:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wc5SB-00D7in-2d for pgsql-hackers@lists.postgresql.org; Tue, 23 Jun 2026 18:02:31 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wc5SA-00000001mS5-1Pbj for pgsql-hackers@postgresql.org; Tue, 23 Jun 2026 18:02:30 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-845385adf4cso200027b3a.0 for ; Tue, 23 Jun 2026 11:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782237747; cv=none; d=google.com; s=arc-20240605; b=WKi/cRgu1GooQUzcZRy9xmFaG+hi4Jd20EMN33VWOujWN9SeobbXqp73LBWplcu/eb 4eGBzv9k08oiNF/fttcOSgrc6NB8IIcBDVJ9HV+mhHZf9b1RgHQTTfCMLiK+VomfF0Fq 7Tra4guB9zcMfdVx/5plJEnl/7bnuRPsz16my0Fk4OoOjBEPFWF4LvgIVUi+7886MGZN HIW/Dkyn2/O2MtigjB5APhA8+ZqXPDHbnOq5GJuwCu78oqJ6vV1nBkRcWpdh2LrCSXtR hOrtvpJefN8ry7LIYv8PmyHQJWMnjZUtYHMUZLeehycFZzd70uJUSI2xQ08nEerpAk48 8ZaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Fc0MI54QmZeXSuIbByd0/5L10ozgCRmfx3KUIKqM22s=; fh=7ytY7TAhCMrlchSqFJFkawg3LIsDf6BInzGvGS0I7UA=; b=anydFrNvzHbwlHphKJt6ZUDa6jV6wlWOgq3tPorEAWme9a5ctBKdr4Lm92Ac+LwrGL TyTwBfg5o9twbPxa6ff/tXbrL374udSryQeaRfMs+jDoRNNmuZsTLqH/eEnkozSQxWtP oC88Bpjo0Fnphgt6PnKcBLYOSXYIwlGDVfHWO1TlaeuK1nWUbtOLl24Y/8zYN06mGl9j XBZzSluOz++5WrEGYJQJEg0kyjTaxcKqLRPdrjyQp6m7U/cPjyIL7WxUCMYsDGdNx4mD 2OfJcOXZUxAI7nzY/HwQxHMe8a/RkFGevlxT0/+F+ikK104w4LitY3OhRRVONxX6hmBq zCJQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782237747; x=1782842547; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Fc0MI54QmZeXSuIbByd0/5L10ozgCRmfx3KUIKqM22s=; b=YtXb84Iu9jFhx8QZdqoizV3xwb4+j0c19FZxWqy+jU3UWvwxL3HfSWFHV+Ki67I9k1 EkcmU2cGD/sBj0flPcvgq+CQbQxdJ7QLp14NFAXGIRApuXFKgjMnCJEy36wGO19wFCZ/ mUoBYkQLpIublEYqpgxt9tIbsHjSLxdUN3R0mpZahnn08Z9XIq1RadbRuttBYCJdRIdu ZT/hVUeyNnjZO6vy4UABD9J35vccc1CRYUs24GdkwNRzcGdnuYulLBbcwV7jwl/En9Qw gJHBhXPPDJi8+7S6PH7ZhMeT1EpGAoUfy9AlgMcQFu/rw1UU84CiT5Oc+WG0d3Ytd1ku Bacg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782237747; x=1782842547; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Fc0MI54QmZeXSuIbByd0/5L10ozgCRmfx3KUIKqM22s=; b=cEZis9cWSGMWTU6av+eoqDp8iTyh2SJdxAEAIh77sIUc2RPThHNqFzGDyjzz/bby0M zPfphywXbx8KKUlNSzBRKbXiM06lZS/oLbYhRzqSb99tsHSATaqeOEXbwXCynYQwqs6p Q7KPHWGX+AZXZOkNyWIsyiaMBM82TIi9/l8WnKnnU+7g4YO7X5pxFqODdOMyEp/3jpVA CO3pxiBQYrM4DEJi03diIDBjTffg2ee1nm0uoGwpykdVyj6r/gUdqNco8Ya/45m25X0C UUufzzQsOdSJRR9LVvKFmTOE8GM0KAum0/6oyzOXbNKPThNDWVmGr52IdL3wgjOuwa+e tTlQ== X-Forwarded-Encrypted: i=1; AFNElJ9HkMb9U7HuX9qeFsmtkHvlmvy9nkgM7DyQLZK7zLpItyn5vdk7pDEQ8tKNiXgN258P8mOSWoF0dqaPInxS@postgresql.org X-Gm-Message-State: AOJu0Ywri2oZygOjf9Q93Bk+ctk5RraP7uQwsUxVLeh7zxr8efRfZ8s+ L/5+YKgb6RbtaXnZfPnjkq01kZmlSrgOP8u1WEp6eynn0+O8RLuYmKH/Ced+b7kQYmVfBw//rE+ ZLl8YVmshS4/j+YM60Y1WaCOdkJm2iL4= X-Gm-Gg: AfdE7cmyZWYOtjkSYILU2lramCSb9YukXOi0DJBOL/Oqs8AV3ujp/eO3nmxPKWrEbsJ J/vlIyodk4GmbOR/lra9nWfbkZPIBDiPZdS73bl2v+zF5tQY57GNoMs46DRIS1I7ae5JjfU9n9P HMZMWynATeMyGLplquW9UwbcVGsGies+iI9KWPykqx332zM0UOi0Cc+NBr5uqowrowLoRg0oMxP dbPAig/Up9L4A6Q+pRIyjNsdbvEnYWiQ8ZLVTaxgwZi9p72aGfQLYeOTNPSlLFu5eFdZLRN9eVI Xe4nhjdr57cR70FEEZ9Vs8dR3gxUgw== X-Received: by 2002:a05:6a00:1ca0:b0:845:259f:8925 with SMTP id d2e1a72fcca58-845a26dbae0mr219267b3a.6.1782237747316; Tue, 23 Jun 2026 11:02:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Tue, 23 Jun 2026 11:01:49 -0700 X-Gm-Features: AVVi8CcVcGIgm4enThbsLlPZ0wG0xWe8hXcbJIYigXtNlP_m7R6e0gNKMn7Btmg Message-ID: Subject: Re: Add a hook for handling logical decoding messages on subscribers. To: Amit Kapila Cc: Bharath Rupireddy , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jun 23, 2026 at 1:52=E2=80=AFAM Amit Kapila wrote: > > On Tue, Jun 23, 2026 at 4:09=E2=80=AFAM Bharath Rupireddy > wrote: > > > > On Fri, Jun 19, 2026 at 3:34=E2=80=AFPM Masahiko Sawada wrote: > > > > > > Hi all, > > > > > > Commit ac4645c015 allows pgoutput to send logical decoding messages, > > > but it's limited to applications that use the pgoutput plugin -- the > > > built-in logical replication doesn't use it. I'd like to propose > > > introducing a hook to the logical replication message handling so tha= t > > > extensions can plug in their own handling routine. This feature can b= e > > > used for extensions to implement DDL replication, function > > > replication, or trigger user-specific routines on the subscriber side= . > > > > Thanks for working on this! > > > > > I've attached the PoC patch; it adds a hook function, and adds a new > > > 'message' subscription option that allows the user to request the > > > publisher to send logical decoding messages. Therefore, users need to > > > enable the 'message' option and set up the hook function at server > > > startup in order to receive the messages and trigger the hook > > > function. > > > > I understand the intent of the proposal, but I'd like to get the > > bigger picture first. > > > > Do we have any external modules that actually implement DDL > > replication (or any of the listed use-cases) with a similar hook? Or > > any existing discussion? I could be missing something because I > > haven't looked at all the DDL replication related threads. > > > > Another thing I'm curious about - why a hook? Is the plan to implement > > DDL replication as an external module rather than in core? If DDL > > replication eventually gets into core, I'd expect it to be apply-side > > logic executing the decoded DDL messages directly, not something going > > through a hook. > > > > I think it is important to have some example extension implementation > to see how the hook could be utilized. One more use of such a hook > could be to use for audit of DDLs replayed on subscribers. Right. I'm implementing a basic DDL replication solution using this hook as a sample implementation. Other than that, this feature can be used to add additional information for the replicated transaction that is not replicated via logical replication protocol, such as the executed user or context-specific information, which can then be dispatched to a CDC system connected to the subscriber. > BTW, can we > also consider it as a solution implementing basic DDL replication for > tables? The key question is what if someday we have in-core DDL > replication. I think extensions can still be used to implement > filtering or transformation of DDL. We can implement capture of DDL > using JSON format [1] so that it is forward compatible with in-core > DDL replication. So considering that, the extension handlers will look > like: While a common JSON format might be helpful for forward compatibility with in-core DDL replication, I think that we need to keep the generic logical decoding messages used by this feature distinct from the messages that would be used for DDL replication. A generic logical decoding message can be written via pg_logical_emit_message() SQL function, which is granted to PUBLIC, so any user could directly emit a DDL command in the JSON format with the 'pg_ddl' prefix and create arbitrary tables on the subscriber, which could cause a privilege escalation problem. I don't think we should build something as powerful as DDL execution on top of a message channel that any user can write to. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com