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 1vVzJb-00AKbl-0s for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Dec 2025 21:44: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 1vVzJZ-00Gren-2e for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Dec 2025 21:44: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 1vVzJZ-00Gref-1G for pgsql-hackers@lists.postgresql.org; Wed, 17 Dec 2025 21:44:10 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vVzJY-001Dal-1o for pgsql-hackers@lists.postgresql.org; Wed, 17 Dec 2025 21:44:09 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-34ca40c1213so2951596a91.0 for ; Wed, 17 Dec 2025 13:44:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766007847; x=1766612647; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3zXrKN9lG05NqIVUTOObZGFYiug3BiYj1se6xKs2i2M=; b=b+FSzijH5bSiNzQ13r2oVNFXMS4jYwNJD3a9U0pBVIjMmlZFREti+hNBfpaZ4OVYLN 2XdidwF+O2mvtbmDKmSQYuyJPuMx1MdXOWxh+gG9M4MFBxkCnep6EM4IDEcnlIfp7P7c EXV0lum6HBHjO9X+ZjDXe0XdSpTHKo9z+hUf6vnbSawXuFXEfFWf4paBs07H9vfaZzQ2 ykSmPaHnPRIMGMIFmuzfL7EAnNit3j9aIpo0MNKpzIXeL3sE034CBDWpfWTR/YdH+UlH 8X94ErujRyBArJpgS1ZRHAnjvsanLE6bFQg841/SRchjdChB6/Jhig5wm0cKw1YlRvZ6 vDaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766007847; x=1766612647; h=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=3zXrKN9lG05NqIVUTOObZGFYiug3BiYj1se6xKs2i2M=; b=Q/6JzCp+772z84tvlQZudPSrLUszr/yjckyrZ3Npy1Gf/iodPr9WQZvuLQZcN0SNiZ DfQ5mI9cISTqYaTe6OTm1csEQ7B0KQxDUIEKwXORuSxhc3DlGSYelnlHZT1JrKc225uO Ih6u68bwXVZSaLSAsP8GZlvAHVTfUX3QGGypEsXvtnObgHz+ZKmtZhxp9XWNnEVZ/LIp k3Hrcags1eaRjs9HzCS0BWgKi+BT9tG/RgF4dN7aHfFAhWvVh1iMs9+Ueq7fLIBm5Flm QRqUvkjgyeqR++bGZfV8LIVJLV2CGoOKPGUf344D2Wg8cKB/6tsXVFCqtiqye+qur92f 2o5w== X-Forwarded-Encrypted: i=1; AJvYcCVLwsPNB1qVOE2Ngt9oBRhUu/1q5zYE7fZe14sCE0r22WIdTdFtlRNNXF5uC69aj8zAyUruLdscvt6IMuAW@lists.postgresql.org X-Gm-Message-State: AOJu0Yxg51ED0uKPDJeGmsOb2PAquJD2fs+AvBRvKLJ0byefdp1owDgh Vc/TnntMdo3quPsNVd+njMtNjCyO6j4yT4GpVqigcB4it5ySUbizY4ZrnKmChpHMYo061aXv6GX iWIwvCYnpITPDC0tYn1kjZYhnCJsqlW8= X-Gm-Gg: AY/fxX6nY0H7VB18PYb+kDmI7NscGhsRiBqcz0/vwXVgLwKfQU3EIxpyNuqHCvtjDfj cDIMdZMjntF1Q6qhxqPxnA5EJf4Z+56fnTlZVMU+ULsNW8u5awXPviecYZKqhg89z6+5cU+SBpx lWk2SBU8LAzbWfXwypgPDaqOGJGYIoX2CIaGQXLpJBtJBKzffAN7XiaRIFXFsh5DjaahLmlklkN n1rDIaEM3ZTvfouSm0Kj95ZHJpAZyKlAYCu50lV+S4ISnRwKioloHm6yL/qvzUKxOTbNpdjUSCY L9+mmsiUPmjc+f1Z4a/zZuP5pl17 X-Google-Smtp-Source: AGHT+IE2rs9nql4Ht5gGv9bNz72Uciu71TfH5oDuoTURLYMCOvXR1MAA+qB1BzTbBmzKW5WbLizVsVeRiZmpNoeWOVA= X-Received: by 2002:a17:90b:3949:b0:32e:a10b:ce33 with SMTP id 98e67ed59e1d1-34abe478148mr16606708a91.21.1766007847013; Wed, 17 Dec 2025 13:44:07 -0800 (PST) MIME-Version: 1.0 References: <5ABD7727-CD22-4112-A186-0E788EE78109@gmail.com> <23A24BFF-18A7-4FE9-AAFA-13E1AA207DD0@gmail.com> In-Reply-To: From: GRANT ZHOU Date: Wed, 17 Dec 2025 13:43:31 -0800 X-Gm-Features: AQt7F2rb37vuG7SpFGiGUbgJ5rT17l2nQmfi8hZOLV0pELS5J9jMcd-o9nB8zmk Message-ID: Subject: Re: Improve logical replication usability when tables lack primary keys To: Euler Taveira Cc: "houzj.fnst@fujitsu.com" , Chao Li , Amit Kapila , Dilip Kumar , Postgres hackers Content-Type: multipart/alternative; boundary="000000000000644ee706462cbeae" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000644ee706462cbeae Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 17, 2025 at 12:50=E2=80=AFPM Euler Taveira = wrote: > The ship has sailed a long time ago (version 9.4 to be precise -- commit > 07cacba983ef). The row identifier property was defined as an SQL command > (ALTER > TABLE ... REPLICA IDENTITY) and *not* a publication property. IMO that's > the > correct design because row identifier is a table property. Extend this > concept > to a publication property is the wrong direction. It is confusing and > complex. > Thanks for the detailed history. I completely understand and respect that Replica Identity is designed as a table property. > Each table needs to say what's its row identifier. The user created a tab= le > without primary key. Well, create a primary key. There are dozens of > thousands > of objects. Use a script. However, I=E2=80=99d like to share a user perspective regarding the "use a = script" approach. The main value of FOR TABLES IN SCHEMA is *in-database automation= *. If users still need to maintain external scripts to monitor and ALTER new tables to prevent replication errors, it significantly diminishes the value of that automation. Additionally, tables without Primary Keys are valid SQL and extremely common in enterprise environments (e.g., audit logs, data warehousing). In large-scale deployments, enforcing PKs on every single table isn't always practical. > I would suggest a way to disallow or add a warning > message while creating the publication or adding new tables, however, the > FOR > ALL TABLES and FOR TABLES IN SCHEMA were mentioned. There isn't a reliabl= e > way > to guarantee that a publication with UPDATE and/or DELETE option contains > only > tables with pk, RI FULL or RI USING INDEX. The fact that there is no rows > in the > pg_publication_rel for these clauses, makes validating the CREATE/ALTER > PUBLICATION commands more difficult. (I prefer deterministic commands and > when I > saw an object definition saying "including objects created in the future"= , > my > first question is: what's the drawbacks and caveats?) > > I don't think the current behavior is lacking documentation; the REPLICA > IDENTITY concept is explicitly in the logical replication chapter [1]. I think the goal of this proposal is not to change the underlying table property design, but rather to seek a mechanism (like a Publication option) to ensure this automation functions safely without external intervention. It is simply about allowing the database to handle these valid, common scenarios gracefully when automation is enabled. -- Grant Zhou Highgo Software --000000000000644ee706462cbeae Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Dec 17, 2025 at 12:50=E2=80=AFPM = Euler Taveira <euler@eulerto.com> wrote:
The ship has sailed a long time a= go (version 9.4 to be precise -- commit
07cacba983ef). The row identifier property was defined as an SQL command (A= LTER
TABLE ... REPLICA IDENTITY) and *not* a publication property. IMO that'= s the
correct design because row identifier is a table property. Extend this conc= ept
to a publication property is the wrong direction. It is confusing and compl= ex.

Thanks for the detailed history. I completely unders= tand and respect that Replica Identity is designed as a table property.

=
Each table needs to say what's its row identifier. The user created a t= able
without primary key. Well, create a primary key. There are dozens of thousa= nds
of objects. Use a script.

However, I=E2=80=99d like to = share a user perspective regarding the "use a script" approach. The main value of FOR TABLES IN SCHEMA is in-database autom= ation. If users still need to maintain external scripts to monitor and = ALTER new tables to prevent replication errors, it significant= ly diminishes the value of that automation.

Additionally, tables with= out Primary Keys are valid SQL and extremely common in enterprise environme= nts (e.g., audit logs, data warehousing). In large-scale deployments, enfor= cing PKs on every single table isn't always practical.=C2=A0

<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">I would suggest a way to d= isallow or add a warning
message while creating the publication or adding new tables, however, the F= OR
ALL TABLES and FOR TABLES IN SCHEMA were mentioned. There isn't a relia= ble way
to guarantee that a publication with UPDATE and/or DELETE option contains o= nly
tables with pk, RI FULL or RI USING INDEX. The fact that there is no rows i= n the
pg_publication_rel for these clauses, makes validating the CREATE/ALTER
PUBLICATION commands more difficult. (I prefer deterministic commands and w= hen I
saw an object definition saying "including objects created in the futu= re", my
first question is: what's the drawbacks and caveats?)

I don't think the current behavior is lacking documentation; the REPLIC= A
IDENTITY concept is explicitly in the logical replication chapter [1].

I think the goal of this proposal is not to cha= nge the underlying table property design, but rather to seek a mechanism (l= ike a Publication option) to ensure this automation functions safely withou= t external intervention. It is simply about allowing the database to handle= these valid, common scenarios gracefully when automation is enabled.
=

--
Grant Zhou
Highgo Software
=
--000000000000644ee706462cbeae--