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 1wHqIt-007Ykr-1B for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Apr 2026 21:49:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wHqIs-001EAg-1N for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Apr 2026 21:49:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wHqIs-001EAW-0I for pgsql-hackers@lists.postgresql.org; Tue, 28 Apr 2026 21:49:14 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wHqIp-00000003ay1-1j6M for pgsql-hackers@lists.postgresql.org; Tue, 28 Apr 2026 21:49:13 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-35691a231a7so7946410a91.3 for ; Tue, 28 Apr 2026 14:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777412949; cv=none; d=google.com; s=arc-20240605; b=JJeqAZhqjcvM2aEL+d1aMymVhBYocKMgSkuemHCgXpMRVdkkQkt703DPts6R1LzzUg b/X1Eq+MFRfO07YcpXZgx0N0DMzXMMmagW0stmaG0HEzBWN0pmy9PQ9tHZvL7bOFZPkY SX5o+PY/dWxKItYQvE6oz8PTgY+X9G2MfwC739gwqlRJDgKFPxJrznKnmDWZA0C75sIe f3Ys3N4OwMVekbtwgSVQOBqsDdaf2KkWDul8gmY4hu4eXMkczC1EcwdwnicRiNkvLOEA fEdMq+vp2hXZBjWZYHRy4As9GDelkoGTbPtQ6RMsAa+WBJymGBNRz3Wzs1iG7HenHCeV fhow== 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=X6HRfq7mPGffJeZpEBbW6RFlIFE8zX3r05T2bruPcmA=; fh=T1KPy/JJrgYKob9B/9X6NvAkUVX82S4XqEUvyS42X3Q=; b=DbUEh9Oi/P8W74mJJCIJR79Bi3aQ5D91CCNScebjo422H+9kL6fDVAjGhF+L/M+vEW EWoc7s8BASq1Bu8QO2xXuQmrjSsoXq9KitzEx0KEXlO8uDojw5vGiLHtqUuloc/Ees73 ZyR92m+h/XavkVFUk1uobo6bQovfhG/OOYld3L2EnomkbYg5Fx6xG2wdrZ95HlXT6uQh yB39+O1ydui6rrvVwcJVsDNjUOti4cXE65sfYMT8fo9MxLjhGSE4WYRFORptO6MWriss JdVPJKJihoJ0YBPviy/WPRTMhcCWaME7umlbAdr+AEYlAJFjUhZJj6ArE3OqtubzMm0C dnLw==; darn=lists.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=1777412949; x=1778017749; darn=lists.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=X6HRfq7mPGffJeZpEBbW6RFlIFE8zX3r05T2bruPcmA=; b=jj856hXFi0CpH9RwVyhorkgMO66BFGxqCnjVsjl1R093pVhS93zp6QHhig4b4bbO0y DIhqBz4zxn1OuPAYA9HGTQ7r8h2v4axLYqI7WHoDHuT8B9ins+buUejM5W6c2kTJLkdn Yy4G5CWz6BVJxFHO3BFCdK+LsTnkV7oXBgd9ZQKCSa0DLdi4XnN6vHhqz74aypIEvwAj uSQkQVUnRVRqBz5PEpBwaQiiLivRY7uZfuNWEaPx5iDM+RM8a04eaJY+GXQKezpjvfhu 7HzEKAgCCNlZBLIYt1n+TK0ZM0q+T+ybmkCuVoGYDC3fUadeBRTPFlEL2aNJLlH2X+yp IIBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777412949; x=1778017749; 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=X6HRfq7mPGffJeZpEBbW6RFlIFE8zX3r05T2bruPcmA=; b=sNfz9EQCsvgkRe2SlxkVHg55vRmjQloiLMICCDq77fv4qYvVvyL5yDjh5/wRhSy4ib RKBPE543Sboztl5e+qNpPkYuONizKt+9z+o+xCheOAKgAzB/rHj+L8wu7pwNVYCeIm5m hHJv69hcADcXXYbFi4MBzoltwasY5n3iIt6RfvMo8pKqVumUVzVLz13UIgfJ0Z7lkLc4 EAYV0rwYM8oQhnoTKirL/+D/s+kAawxdnTfAMsKHb28vWXIy0xOM/LPGDbsD1K2I6L6O NjjdzN+EvpzRo5moWGNTdj3vxit6eQjnwVHbbfPSGAtpX1QTPNemcBuc8j2GJqE6U3C6 Ut2A== X-Forwarded-Encrypted: i=1; AFNElJ+JUTXkYliTk5HGKwFkbgQ6SNQo6ySkwiO1vAHB5Zp7xiQ+RwSX6UyQjzHTi7vwktL1GmPjA6ABdGcpKVbf@lists.postgresql.org X-Gm-Message-State: AOJu0YwXLoSxNarSzNGdjI4blNkGvAVK16gXfKjCny6LRsWASKreY8bs 0HUofp3jSmo8dHr+XLgxK9qx2JK+0nHm1U9ki6o/ZYFS+Plt/ibA1DiYvC8RcUTRtOYMgiSffTh 7/mHKhj3N9JztgklXmWgp3KWvi5wWpi3D0p3lQCc= X-Gm-Gg: AeBDietSKy7WgmlYVOhwdNzvJbIQrvunATzA+9MCo9K0H7uY4SJYLpIkiESljwnxNKK yoWPzDJIGsq4MPvmFz/kYNUtK7cDHV+7UEQxNl4HTMfvz5VMhP/ACHOdQY5y4xzvbOMv484I4Xf Y6w5kpIU9Uy1WwpucfOx0nMYPQM32nDsIHWCp2fnUNZPDokhEn5RkpbbUhePx8C+ZfVxm3Md/OH psFOmw/BZuFkOEF5LNHU6wDdt8Zqg8CfnwaHAx1P0uRTF6k7PTMd38N/5Twr4KyUi3+j/9GXPKN Gcvh0vPqFANLIuWp2EvKMO1Gu9dnuD8ZAFUdBlNQFFDrbk/mIi0= X-Received: by 2002:a17:90b:2f8b:b0:35d:ac4d:3cb6 with SMTP id 98e67ed59e1d1-364a0b2db06mr1099730a91.5.1777412948789; Tue, 28 Apr 2026 14:49:08 -0700 (PDT) MIME-Version: 1.0 References: <080f9394-c127-4cef-865e-10f2f997125c@postgrespro.ru> <38690b0e-f91b-46fa-b72a-57775612e463@postgrespro.ru> In-Reply-To: From: Masahiko Sawada Date: Tue, 28 Apr 2026 14:48:31 -0700 X-Gm-Features: AVHnY4LlAzpXH0ljnI8TtpGsJDYnRLvzCbAeB8AWGsSyXCbqh1g_-ETysSwpyso Message-ID: Subject: Re: Support logical replication of DDLs, take2 To: Amit Kapila Cc: Vitaly Davydov , Ashutosh Bapat , PostgreSQL Hackers 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 Mon, Apr 27, 2026 at 11:32=E2=80=AFPM Amit Kapila wrote: > > On Tue, Apr 21, 2026 at 4:45=E2=80=AFAM Masahiko Sawada wrote: > > > > On Mon, Feb 23, 2026 at 5:21=E2=80=AFPM Masahiko Sawada wrote: > > > > > > > > > One idea I'm experimenting with is that we define an abstract data > > > type that can represent a DDL (like CollectedCommand) and write it to > > > a new WAL record so that logical decoding processes it. For CREATE > > > DDLs, we can use pg_get_xxx_def() function while using a historical > > > snapshot to get the DDLs. We would need to implement the codes to > > > generate DROP and ALTER DDLs from the data. I believe DROP DDLs would > > > not be hard. For ALTER DDLs, we would incur the initial implementatio= n > > > costs, but we would not change these codes often. > > > > > > > DDL support for logical replication is one of the biggest missing > > pieces in logical replication. I'd like to resume this work for PG20. > > > > We made a lot of effort on this feature through 2022 and 2023, but the > > development is currently inactive. The last patch was submitted on Jul > > 18, 2023. I've reviewed the previous patches and discussions, and I > > would like to summarize how DDL replication was implemented, the main > > reasons it stalled, and propose an alternative design to address those > > problems. > > > > The overall idea of the previous patch set was to implement DDL > > deparsing and utilize it for DDL replication. It converted a parse > > tree into a JSON string. For instance, if a user executes "DROP TABLE > > t1", the deparser generates from its parse tree: > > > > {DROPSTMT :objects (("t1")) :removeType 41 :behavior 0 :missing_ok > > false :concurrent false} > > > > to: > > > > {"fmt": "DROP TABLE %{objidentity}s", "objidentity": "public.t1"} > > > > This JSON string is self-documenting, meaning someone who gets it can > > easily reconstruct the original DDL with schema-qualified object > > names. In a dedicated event trigger for logical replication, we > > deparsed the parse tree of a DDL, wrote it into a WAL record, and then > > the logical decoding processed it similarly to DML changes. > > > > While there are several benefits to the JSON data approach mentioned > > in the wiki [1] -- most notably the flexibility to easily remap > > schemas (e.g., mapping "schema A" on the publisher to "schema B" on > > the subscriber) -- there was a major concern: the huge maintenance > > burden. > > > > Yes, there will be a maintenance cost of JSON-based deparsing > approach. But note that multiple senior people (Alvaro Herrera, Robert > Haas) [1] seems to favor that approach. So, I am not sure we can > conclude to abandon that approach without those people or some other > senior people agreeing to abandon it. To be clear, I am not against > considering a new/different approach for DDL replication but just that > it is not clear that old/existing approach can be ruled out without > more discussion on it, Thank you for pointing it out. Just to be clear, IIUC what they liked was to use JSON string representation of DDLs, but not JSON string representation of DDLs that are deparsed from parse nodes, no? I think if we do versioning the DDL commands sent to subscribers, we can support JSON-based DDLs in later versions. > > We would need to maintain the JSON serialization code whenever > > creating or modifying parse nodes, regardless of whether the changes > > were related to DDL replication. IIUC, this was the primary reason the > > feature didn't cross the finish line. > > > > Additionally, I think there is another design issue: it is not > > output-plugin agnostic. Since the deparsed DDL was written by a > > logical-replication-specific event trigger, third-party logical > > decoding plugins cannot easily detect DDL events. > > > > Why RmgrId like RM_LOGICALDDLMSG_ID and XLOG_LOGICAL_DDL_MESSAGE wal > info is not sufficient for this? Decoder will add a message like > REORDER_BUFFER_CHANGE_DDL which can be used to detect DDL message, no? Right, but I'm not sure this is a good developer experience that additional steps are required to capture DDL events for other plugins while changes of INSERT/UPDATE/DELETE/TRUNCATE are passed from the logical decoding by default. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com