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 1vnXUq-008XlX-2b for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Feb 2026 07:40:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnXUp-009o24-2j for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Feb 2026 07:40:19 +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 1vnXUp-009o1t-1h for pgsql-hackers@lists.postgresql.org; Wed, 04 Feb 2026 07:40:19 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnXUm-00000000zSD-3kv4 for pgsql-hackers@lists.postgresql.org; Wed, 04 Feb 2026 07:40:19 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-59e2cb21520so3081413e87.1 for ; Tue, 03 Feb 2026 23:40:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770190816; cv=none; d=google.com; s=arc-20240605; b=PzfxQgHFRpgSwEr+MSYa2JTNzae6YhbaRaJ7Fyfa8ENo46xqVHW3dOAW4A1yDE+W2e a448V7ioHLR8VRQ+HAXx+4tUPw7HB0dvaTvLKXNy3ju+1pm4DNErPu3cAlGA10JSpWo9 mFTWwpZaR9r6iIZKMFoDIZzX+V1LZrrudWpcT8abfBFm03UDCnxqIO5LN0zV34peYrot n0aqoFKBHh//vARVKYHdPoGwvLRk9T06Zv5cgFFbegQuQa8jWdQ/cedNeuMYZdxRSN/U VFMlMRWNtVhEnIhE4DoPJiPjItN2487l4a/HZcwb4EsoXTN0vFtAKWgnr80T8rHPCPSk HgDg== 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=Xoqhcn7AubSkr6q2Cw4ATuYAfh6zbmeqpr3w70qXawg=; fh=TWOW6pcG+2B//k4gBj/tL1xzyXmOsQD52mW4JZgqdwY=; b=IikilWp7a2GWdV6TuBKD7WLxsM2QnIXQ7mHU88GS/IJrxORTdv09HdxucZHXcqcja5 WRuYDUeHTGZHQwOLwILmdGBPNyBPcsCeFVReKi6u4poakGxKZElOnJETX7EcE7bYVo/2 KJkdfhl945kLo8m/Lyk1ZMYe1UKbO/SWfqyVuoDWdu6mGsykgh0hx/X5CekUI68iNtyM OjHCmQzJS0JaS814WUHJJHQVe8zQqNX2Vu7FoGKsCKH5wQCbOT2TqeZ6EftTNgS4oXJU jtdqoq5ud0rofvf2kHjQdVVQ6H/NTQpAEhPhCfaHnJyQC56SbmXWHJIwBLOz5F2g/IPs efKQ==; 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=1770190816; x=1770795616; 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=Xoqhcn7AubSkr6q2Cw4ATuYAfh6zbmeqpr3w70qXawg=; b=IUwB0NelV5k3JbP9EQkTCi7l02+G4pg3v4iLYZQjpbjPNGI7SqEu3frKSz47VVM8Em lKr26qCdZZBbZzFXAccNeeuhyFggcV9zkrPrmfy39xRCzBr5TExAT8UYY1VvmfMRfBF5 S+WZ+jf6Xj0jpFcqXU0eJ5Tb1r5URfv1Y6UCLh3OC/h3Nxf1d+TKDlU80/zpS4lAbFji y2lBaJANJ0DH4zTBieNmLgiTpphMf5cPBmPgzWf0yApwmJhPVRvjf7cjnxl1ZTpO38ZM SObGkD2feXaGHYU+vFvt9ZdSmJ6J3YroRDZQUnBdFpaPow5kdRMJ0/BMOtcoGFUs0L/a T33g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770190816; x=1770795616; 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=Xoqhcn7AubSkr6q2Cw4ATuYAfh6zbmeqpr3w70qXawg=; b=FV4IRaHp1X7btktbUl+BdZZEt451gTGpHiptSlKxkv4QI2PHAb6GvzIqIO/H49PI6T yYGOo85I3POsYYmSRhB9+Lp7QhetiUNiR+jlMGw/ZGy4/Q9He2XTcn3HRCLuCF5IVXhv ZKzCSskDpJgWdmJTHXywSzJomBaqjEzVe51JwjDuIM9ldpQ+au/GotK88Yq9o0KeIgr7 b1Nf0vnf/zySkf0ZN3jl4gR95UVP7foVGE2xyRa3VP0X2GLNHZoenwwS2OlsNrEzdas7 XpReCOUG+FNsnBjqS+gZjlgea7KspQrTLztxh90Crwod4gUO6kk/4ru7XTFyw7AztDN7 uJKg== X-Gm-Message-State: AOJu0YxYKCMTh5X90eOsmfsjKhGea2Es1Lr7ymzsON8ZWZNEQSDTtnFV 4Apqm3HzF0FbgeL/nSdN/yx+1V7EXSz2W56XUAVaecEe97hCiNzaK9cfkUJTsgOHYS2VQKCGWEE 9CoFbDtgoK9+SCmVrzLRJH4ir3f+URI9XGeAd X-Gm-Gg: AZuq6aIJBIV9YoivSfQazyhdQ4ycQL6gtZAw33j1P2o9EL6UzRr0miPqiRpra/rNc4t MjXtIariVFv4Z2lA3OTs0+zo3QXc+HQlr2mkYP39tsFsBj43KN0w3t59HiJQnhjw/S+NyjBdw6P nJSo6fGAOmpt6rv6FFyMNFUdLOl6/p/vsMLM3cP3ETZBa2qrW1luREG1tURTS0RiTB59/3SC3Te DiqNiNFk34lyBEU/BhqlHQSprVJJzLZInRhWHe831MJtH/Rr3oXO0mnBafEYnEeSjknI3WFLM7N PS+YLvsYJ+mc3a974j+cie0IkJQgniIRFAzL X-Received: by 2002:a05:6512:4001:b0:59d:f2f3:7e9a with SMTP id 2adb3069b0e04-59e38c35817mr671386e87.36.1770190815359; Tue, 03 Feb 2026 23:40:15 -0800 (PST) MIME-Version: 1.0 References: <080f9394-c127-4cef-865e-10f2f997125c@postgrespro.ru> In-Reply-To: <080f9394-c127-4cef-865e-10f2f997125c@postgrespro.ru> From: Masahiko Sawada Date: Wed, 4 Feb 2026 16:39:38 +0900 X-Gm-Features: AZwV_Qj9LwMqVO0x1uYGNP0QZWQZg_hd7z98uZB7nnyfhkuM657Y9dYufIz8uO0 Message-ID: Subject: Re: Support logical replication of DDLs To: Vitaly Davydov Cc: 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 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 statements = with > the use of the utility hook, convert it into a json-like format, save it = in the > WAL (xl_logical_message) and send it to a peer using the logical replicat= ion > subsystem (walsender). This approach has a major challenge that was alrea= dy > highlighted: DDL statements may be too complex to convert it into a json = string > (for example, unlogged/temporary objects in DDL statements). > > An alternative approach, that was highlighted in the discussion by Dilip = Kumar > is to decode system catalog changes. It helps to deal with complex DDL > statements containing temp objects and to work with a final representatio= n 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 logical > decoding (introduce a new wal_level =3D logical_ddl). I think, not all sy= stem > catalog changes are needed for decoding (not sure, we have to decode pg_d= epend > changes). > > 2. Implement a decoder of system catalog changes, that can produce a pars= e tree > using existing structures from parsenodes.h. > > 3. Based on the decoded parse tree, we can convert it into json or DDL SQ= L > statements in the output plugin. ParseTree to DDL SQL converter can be bu= ilt-in > into the core. Output plugin can decide which converter to use. DDL sql c= an be > directly applied on the replica. > > 4. Another option is to create json/ddl-sql from system catalog changes w= ithout > an intermediate representation, but, anyway, when we interpret system cat= alog > changes we have to temporary save current data in some structures. Parsen= odes > 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. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com