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 1vnbJ7-009JvX-2g for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Feb 2026 11:44:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnbJ6-00B5eH-2g for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Feb 2026 11:44:28 +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 1vnbJ6-00B5e9-1e for pgsql-hackers@lists.postgresql.org; Wed, 04 Feb 2026 11:44:28 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnbJ3-000000011H9-3Mj1 for pgsql-hackers@lists.postgresql.org; Wed, 04 Feb 2026 11:44:27 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-432d28870ddso428063f8f.3 for ; Wed, 04 Feb 2026 03:44:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770205464; cv=none; d=google.com; s=arc-20240605; b=Q/DfosrQcKS+bIw/SV3x4Qf3oQj1BWWYk+VHbiy7FSIA9Crmjo2fiKbC5WcE25U3gJ uLP03jOtoLa6E5Aip4uC3TLVzIIhshm8TQuqPTSmzuhl8DEUVCVtiLdq8Tnl1B494fqR u5Dw23jG09O5tmot/Z6mMyLIQgMAQ5AsHRWn3/1b+sSsNTYgx/6r9ORwhBcIIvdQh0yW IR8b/cgVAnxDCNkUFMghen0e3SI32SW6VpyHzB/CjU+3ClKUQ4l7slnJ3R0Wd1HqByek I3uyo/HiuHxMdvCT6QBVoM+jIwXKFeKjl4mcnq9tVv+Ssg0PogCGGAC39KF23PsaowZ+ sTbw== 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=bqdk18iWbGOW44YjTBZALfKocAVjyny+D16/wy6QRCQ=; fh=IJ/ygMVGiUp2sJ8X3y78iKvgSBbo+F6paqk1Rp8HxgQ=; b=CMuP5lPjFBBbG6pphcjrhP7+ZxIYQK+RAVH9GnhH+HocGNjt+fQTZlULNlHMS1bp14 HQlOZiJEzSIlRMGZ09ES+/Hf/V459eodWHYyB28y9p3XwgNf5yGjIT+o1THmnilXC1tX Yx9SNvtTHu0n5sC32hOBOY9mfnEmm/olNuRI5LTcdYDLVgDNmBrGb4UeCjmPHs+GnXmF RgLnfmeIKIk7pvYIzLQE/e3+DgftMoBypNSgv7p1G6iC9le7T3mn553PhrDbGT/lTjLy 2C2sYrjeWbpNPdTfB+x99Mdp5/5vlEMmt+M908vzky63OreS/9FD5jQ6YtP+e06j6Zsm lFHg==; 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=20230601; t=1770205464; x=1770810264; 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=bqdk18iWbGOW44YjTBZALfKocAVjyny+D16/wy6QRCQ=; b=GbBAbuK1ucMCRU403uAph0AXuJ4tPs1VTfhZ9CjLi56pCqqu0cZ7Phcm8EJA90Ze2o rmWz7uZWagIkx2rDQSWupWXmN5sG9p3md0mgLzpgggDpRdcVRvo/X9IBzbDeH+Ph3XOU qhET55SSpa/aikeatwNbSD0p8U5C0DS9pntzm1rBoiVJ7BepcNnd5+/gqYiyN5HR9VOP dES7VmmNT4bKVwaOzHWDqboT6cDXNTtNn4XH8UpRiwWlnMTNgt+R5h4zhyJBhdJBSM/o pDZdfQzJVbzC2D/Au5XwZ0FaVdGqHREkLmDTTo1HkTizzlHWPDINiX8Wqfiw6bc/Hr4n n2xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770205464; x=1770810264; 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=bqdk18iWbGOW44YjTBZALfKocAVjyny+D16/wy6QRCQ=; b=XYyXsppXgJH8NK0Dm7KrFIvLiT2zccESvDtVaFNClX89go3JLiDuf5UyhoPWREHcSo /LFIjhACKtpoHAWgZ4Gzgt1hCP93f573UXdtGx7G9dTw8dYFslOeOoqSIJm62y01cp2E hQmDdtf4yFP4983GqssAxpclYESO6TTlWbqyawPI6pNX0Hd6P1PAV2LTq4G8HC3YxgtF 9W5sFEW8qq8NC9xiC22bGy8JtPbc/RScVpe18JtOjDEjqSDFolYx232jYyNrmTQCJ7vq UeY/5NuOcJKuDFIpV+QNwdH81ps4GYBd3vpnbNSDoUINjBHGNIqT7SlEJ8Ihv0uBb83f BSFA== X-Forwarded-Encrypted: i=1; AJvYcCVFZqV1eo6rgG89cWsfUQewLtC7BAkw3s4ay2aq+KrPV8kil7y6UzWph3nUfHwVrl8HGw0olzcpxWWeNf8D@lists.postgresql.org X-Gm-Message-State: AOJu0Yw+HyvFs60ijFExWFFEL0orrBDJbai3P1hgH/dnnYAEfYmO8CJk qOAYruOX4lB3ParnZWu0ty2CORsAhyQuVF1dyaZmARqu7EZT8EkmH8jNztat+tmLXBuHBSqIxZ1 AnsTTtDCNPhYL3lKKakl0uyI7CmwdKymHdg== X-Gm-Gg: AZuq6aK5QDhMnjMM9EJfWJL9rn8yI/ZXOMHFXEntHLda796MDtYx4bM3BSi/hmWTCzS laiVpQ1UfmIIeKgQ2Iuz7lu6Ky72/Az1wB1m6XBdaDF/h2ppHwveeZuq1675q3fJpbC9YuEwl7M 1RdMQEjHwPa5ms6tXw7xiTq9Unp93GicYkeamSNNMi6jyGYB3SL85M6lHHG1xskkBYMq68v7IQS N6oRJpLifp6iFifFN/r/1AWtAUqThiZQtFiDTv5GnWsDYJoiAjXoARaT1+N0IwuWFvMDEaf X-Received: by 2002:a05:6000:4313:b0:430:f3ab:56a1 with SMTP id ffacd0b85a97d-436180592c8mr3809188f8f.42.1770205464088; Wed, 04 Feb 2026 03:44:24 -0800 (PST) MIME-Version: 1.0 References: <080f9394-c127-4cef-865e-10f2f997125c@postgrespro.ru> In-Reply-To: From: Ashutosh Bapat Date: Wed, 4 Feb 2026 17:14:10 +0530 X-Gm-Features: AZwV_QgAmY7MdHMGo9mCGIsWgtmT01osST6hxV7AKahHNX0Yh1UlEA5RnS6dsQk Message-ID: Subject: Re: Support logical replication of DDLs To: Masahiko Sawada Cc: Vitaly Davydov , pgsql-hackers@lists.postgresql.org 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 Wed, Feb 4, 2026 at 1:10=E2=80=AFPM Masahiko Sawada wrote: > > Hi, > > On Tue, Feb 3, 2026 at 1:04=E2=80=AFAM Vitaly Davydov wrote: > > > > Dear Hackers, > > > > I see, that the primary idea in this thread is to capture DDL statement= s with > > the use of the utility hook, convert it into a json-like format, save i= t in the > > WAL (xl_logical_message) and send it to a peer using the logical replic= ation > > subsystem (walsender). This approach has a major challenge that was alr= eady > > highlighted: DDL statements may be too complex to convert it into a jso= n string > > (for example, unlogged/temporary objects in DDL statements). > > > > An alternative approach, that was highlighted in the discussion by Dili= p Kumar > > is to decode system catalog changes. It helps to deal with complex DDL > > statements containing temp objects and to work with a final representat= ion of > > changes stored in the WAL. Personally, I like this approach. > > > > I would share the following idea: > > > > 1. Log into the WAL system catalog changes (tuples) suitable for logica= l > > decoding (introduce a new wal_level =3D logical_ddl). I think, not all = system > > catalog changes are needed for decoding (not sure, we have to decode pg= _depend > > changes). > > > > 2. Implement a decoder of system catalog changes, that can produce a pa= rse tree > > using existing structures from parsenodes.h. > > > > 3. Based on the decoded parse tree, we can convert it into json or DDL = SQL > > statements in the output plugin. ParseTree to DDL SQL converter can be = built-in > > into the core. Output plugin can decide which converter to use. DDL sql= can be > > directly applied on the replica. > > > > 4. Another option is to create json/ddl-sql from system catalog changes= without > > an intermediate representation, but, anyway, when we interpret system c= atalog > > changes we have to temporary save current data in some structures. Pars= enodes > > is the already existing solution for it. > > IIUC, one of the main challenges of the "deparsing DDL parse tree" > idea is the maintenance burden. If we implement logic to deparse parse > nodes back to SQL text, we would end up updating that deparsing code > every time the underlying parse node definition changes (which happens > frequently in internal structures). This introduces a substantial and > ongoing maintenance cost. > > In that light, the idea proposed above seems to increase this burden > rather than alleviate it. It requires implementing not only the DDL > deparsing (converting parse nodes back to SQL query) at step 3, but > also the reconstruction of system catalog changes into parse nodes at > Step 2. This implies maintaining complex mappings in two places > whenever internal structures change. > > I've been researching this area lately and experimenting with several > approaches (including the idea of decoding system catalog changes). > While I'm still not sure what is the best approach for DDL > replication, even with the deparse approach I agree that performing > this work at decoding time would be better than doing that at > execution time using event triggers, as it allows all logical decoding > plugins to handle DDLs consistently. > > > The open question: can we unambiguously decode system catalog changes? > > While it sounds challenging, it sounds promising. ISTM it is possible > to infer the executed DDL command from catalog changes. The crucial > point is how to implement this cleanly and to minimize the maintenance > burden as much as possible, especially because this code would be used > only for logical decoding. Instead of reconstructing the full internal > parse nodes, we might want to construct a stable, abstract > representation containing only the necessary information for > replication. Consider an example of ALTER TABLE tab ADD PRIMARY KEY (id) where id is an existing column in table tab. This will add a constraint on the table and also create an index. Thus effectively two DDLs will be executed. If we decode catalog changes we need to make sure that only the original DDL is replicated; else the apply worker downstream will cause an ERROR, stalling the replication. Similar is the case with CREATE TABLE ... AS ... - we should only replicate the CREATE TABLE and let the regular replication handle data replication. I think we need to somehow annotate the WAL containing catalog changes to indicate whether those represent the original DDL or derived DDL and decode only the WAL corresponding to the original DDL. If there are multiple DDLs in the same user SQL, decoding only the original DDL from the WAL would help. Also we will be able to apply table/column based filtering appropriately. --=20 Best Wishes, Ashutosh Bapat