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 1vVOqx-0020zO-0x for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Dec 2025 06:48:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVOqv-004VAM-2L for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Dec 2025 06:48:10 +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 1vVOqv-004VAC-0y for pgsql-hackers@lists.postgresql.org; Tue, 16 Dec 2025 06:48:10 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vVOqu-000v2O-07 for pgsql-hackers@lists.postgresql.org; Tue, 16 Dec 2025 06:48:09 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-7f1243792f2so2791517b3a.1 for ; Mon, 15 Dec 2025 22:48:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765867687; x=1766472487; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mzxVwUscSTiysOzkztFG3ohkXRA39TwfWu4VvYDF1YY=; b=QwkhMYTDzslPjIT0WrSJT7RDaCncznlu3tS3ZtKzs7oqPMiMveNfWzhBOFkabEMHH3 pnZFUrmySATqSpdj6cV6Bwt793cjOECtCqgfxj6oEsuyel9ZSXhGRA2m8aaEmS6p8zgn UG2rv2pFc2VyVmJ0Thn9JoBUH+tW+yjeTm3CuCfWuvvTzEBqMnXrhr5Bh3hisHzpTCAu 6U2gDGtYSkkvjQjNUISZUgHI3rGea7hkGGQ0gtqGo78zTKRQTxZl9CxsWx/nBAELS/D0 R4ZSSVJXQHQ39AnDZoCxizSCfvYqHgnPHx2J1/e1MqNGYaFlv/zJLmbPFRn8H3sek5Ly Stxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765867687; x=1766472487; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mzxVwUscSTiysOzkztFG3ohkXRA39TwfWu4VvYDF1YY=; b=nncl3vn2bgXQoePb76EGTqHbxIvt/2n9zskcVsRDF3vHC/RviHdZhQHbJ6kt/I63yS 1SHNekRhot2jVpl3jLZL2JWsm7MeZFT3t5BDT0/dTJQVKytXiXGjYpcDO+wMneO89BsE HGNZykACB1CKtonyLjoJhMULjB9EBZSv9HC247ZDPOO2PrhgpBMZPmkv+2Ws26kW/bQw wumaFgKuD8eKIzxYxaOCBa68/hPdeht+NAVKye8eSRtGj+BFzQJ/tdOuzxv0cLzrtCrt P674wBRlbta4dlY/D/YgcWnSPkRSyV4Q3dxS5JcyGIOqK7iVjhQddGUQkm8JFDWL2jwi nRMw== X-Forwarded-Encrypted: i=1; AJvYcCUlMHrV8U0pu+20e4gMmuXJXBAG3NTdONHpwoXsQkNizyoV0aZz9BCXV9wenLoikSh9kz99bCGJcR6vEfsR@lists.postgresql.org X-Gm-Message-State: AOJu0YzCb/Q/O7lNV4VfaSng2H7BV4aZ3zEV3xtNcUGuq4gw1fX7gEZQ hpapMxJH9TzBgUVbWmTgD+9adZu2KaNbuJPa666Lz7b55MIrL7VwLDY+8F22ecoa3Ks= X-Gm-Gg: AY/fxX5QZD8Yaux472DuwjDiC9l00HjEcWNIWrEilLDQVk11/m46JmK4+5MSfwWCtE+ CHLyXUPpd/z6kiD4gJbVJOhVik+jFo68GwJTCCxxH2po49Ysp/hNOHisYzAuff+u3GwI1TW1ZaM lRhVXWPLS2FxY28GA3J9OfytvCWZMLdzE/HR354i07G1WMjOj7TV22TVeW4oan8297cpCQYMrME +9DXtImvKSUfv0KSIjql3Tj9wODiMvBYH2gr0uT9qlCHwJVuMMZJK72DZgRaZApApcHdMZZjnNO 4Evg7/4Usy+5Kq4Y6Y3hZCA3k3bmRPK+tpongpsdkot/EDit2s4Lurz01mXcxK0pdXD82Q0b8iv dbxLleBDPOGLwtVzC1bBewwOQcnIQxNU+5/khc4pOElihFyu8F65JevqbWUNC5tHPhLW3APdae/ DHgBq5jskafEQQYBNbv8xggFaizBYaeg== X-Google-Smtp-Source: AGHT+IGG76AS6KQg877FLlqMUn1n3zmhtIvORIX8rSTaaVh0BC1SEpiIMk6UI5lET1ERdu92wGcuOg== X-Received: by 2002:aa7:82d2:0:b0:7f7:6627:ee8f with SMTP id d2e1a72fcca58-7f7662832cemr6810632b3a.26.1765867686549; Mon, 15 Dec 2025 22:48:06 -0800 (PST) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7f4c4aa9b56sm14404972b3a.39.2025.12.15.22.48.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Dec 2025 22:48:06 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Improve logical replication usability when tables lack primary keys From: Chao Li In-Reply-To: Date: Tue, 16 Dec 2025 14:47:26 +0800 Cc: Dilip Kumar , Postgres hackers Content-Transfer-Encoding: quoted-printable Message-Id: References: <5ABD7727-CD22-4112-A186-0E788EE78109@gmail.com> <23A24BFF-18A7-4FE9-AAFA-13E1AA207DD0@gmail.com> To: Amit Kapila X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Dec 15, 2025, at 13:48, Amit Kapila = wrote: >=20 > On Mon, Dec 15, 2025 at 9:06=E2=80=AFAM Chao Li = wrote: >>=20 >>> On Dec 15, 2025, at 11:28, Dilip Kumar = wrote: >>>=20 >>> On Tue, Nov 11, 2025 at 6:11=E2=80=AFPM Chao Li = wrote: >>>>=20 >>>> Hi Amit, >>>>=20 >>>> Thanks for asking. >>>>=20 >>>>> On Nov 11, 2025, at 19:18, Amit Kapila = wrote: >>>>>=20 >>>>> On Mon, Nov 10, 2025 at 1:36=E2=80=AFPM Chao Li = wrote: >>>>>>=20 >>>>>> * BACKGROUND >>>>>>=20 >>>>>> This requirement comes from several users operating large = deployments, particularly in HIS (Hospital Information Systems). The = situation can be summarized as follows: >>>>>>=20 >>>>>> - A central DB operations team maintains the main database and = configures logical replication for all tables. >>>>>> - Multiple third-party application vendors are allowed to create = new tables in that database. >>>>>> - Some of these newly created tables lack a primary key. Since = logical replication with `REPLICATION IDENTITY DEFAULT` requires a = primary key, such tables silently fail to replicate. >>>>>> - The DB operations team must then spend significant effort = identifying the affected tables and correcting them manually. >>>>>>=20 >>>>>=20 >>>>> Can you share an example of how we silently fail to replicate? = Won't >>>>> in such cases UPDATE/DELETE will anyway raise an ERROR? >>>>>=20 >>>>=20 >>>> Yes, UPDATE/DELETE will fail. That=E2=80=99s the easy case to = expose the error. Actually my patch will allow the update/delete. >>>>=20 >>>> However, some tables, like dictionary tables, they are important, = but don=E2=80=99t have much update/delete, they may silently fail to = replicate. >>>=20 >>> But other than UPDATE/DELETE for what operation we need RI, I mean >>> INSERT would work without any RI and UPDATE/DELETE will fail on the >>> publisher itself without setting RI, so can you explain the exact = case >>> where it will silently fail to replicate? >>>=20 >>=20 >> Thanks for asking. When fallback to FULL, UPDATE/DELETE will be = allowed in the publisher side. In my first email, attached v1 patch is a = PoC that has implemented the logic. >>=20 >=20 > So, without patch, there is no way we can silently replicate the > UPDATE/DELETE. Ideally, users should alter the tables and make RI as > FULL in such cases if they don't have PK for such tables. Falling back > to FULL for DEFAULT when the table doesn't have PK based on GUC has a > downside that it will increase WAL volume by a large amount. I agree that this downside exists, but it is an inherent cost that users = must accept if they choose to replicate all tables, including those = without a primary key. In practice, users who opt into such a = configuration are typically aware of the WAL overhead and make that = trade-off consciously. > I think it should be done specific to tables that users want to = replicate. That is why I mentioned earlier that the new GUC should only be = configurable at the database level (via ALTER DATABASE). However, I = agree that there is still a risk that a user could mistakenly set it in = postgresql.conf, thereby making it effective for the entire cluster. > I don't know what is a good way to give to users who don't want to do > the required setup but if we really want to provide something, it is > better to allow such a thing via the publication option instead. Using a publication-level option could also work. One complication, = however, is that a table can belong to multiple publications. For = example, if table_a belongs to both pub_a and pub_b, and only pub_a is = configured with fallback_to_full while pub_b keeps the default behavior = (fallback_to_none), then the effective behavior for table_a would need = to remain fallback_to_none, meaning that UPDATE/DELETE would still not = be allowed if table_a has not a primary key. > I think it would be good to do such an enhancement if we have more > community support and some other users also appreciate such a feature. > Otherwise, adding something which is specific to a particular user > sounds like a recipe of maintenance burden especially when we already > provide a way to achieve the same thing as is required by the user. Let me elaborate on that point. My company has a very large user base in China, with over 100K = deployments across multiple industries. However, there is currently a = significant gap between this large user population and direct = participation in the PG community. I joined the company in July this = year as a full-time contributor to the PG community, and one of my = responsibilities is to help bridge this gap and bring real-world user = feedback into community discussions. As I mentioned in my earlier email, this requirement comes from = large-scale deployments. The database owners in these environments have = operational models that may not always align with what we consider the = ideal or fully optimized setup, but they are the result of years of = accumulated practice and operational experience. For these users, the = proposed feature would significantly simplify their day-to-day = operations and reduce operational friction. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/