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 1vV1Rf-00C34o-0O for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Dec 2025 05:48:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vV1Re-00Fj8v-0K for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Dec 2025 05:48:30 +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 1vV1Rd-00Fj8l-2c for pgsql-hackers@lists.postgresql.org; Mon, 15 Dec 2025 05:48:30 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vV1Rd-000jPA-02 for pgsql-hackers@lists.postgresql.org; Mon, 15 Dec 2025 05:48:29 +0000 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-37d96f97206so22487641fa.3 for ; Sun, 14 Dec 2025 21:48:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765777707; x=1766382507; 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=i3Tjz1OyYb44h1Ji/kXdAvJhxDyH03vP6XZpDG8+fA8=; b=doJ6acGBtCHV7h3kDoS6k6jbWI0hEmIvpZVCMQE2VYYqn6e6yREHte/JDlKbhCvY7W 2/yeMUaRIETx92qCsT82H7mA8kvIORY/X8rVBx7fcMUig4K0mUdeRbJ2H6srG0LWUH8E j4ZafYkoX0tJNyL6L0/nVPl1PXzKEgb5Gvg5vp3xM9pJeDMwpRI2lKXU9MrHLViMqzr4 RCKMVYpL2RP/Qq0alY5W3JBGDHJTzKS1fI43gVtDDpT1+ypeJrP9YTnkjhWrU3E1igRJ XTKLmFjzrPZtUorhcB+9wFUABzRcc+l2PLYAwl8iLZzew4Tf+E+9AYly87BqPV7ZZ28c IIWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765777707; x=1766382507; 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=i3Tjz1OyYb44h1Ji/kXdAvJhxDyH03vP6XZpDG8+fA8=; b=mUPyg8hEwmW3qnMyUu4Ot+himmip1AiShBh0r+++yR2BF6iE68PuCdCsT7VX52tvVx eWdukjJDahFFTsV1o73oLuhZRcW042V7+AteF0ZAKtN1WfCGtIS3MV58veEuT83hjbIs SPzCyMkS/Mjr0W3mXtpyBk0XwPyetwPLELgHJO2INSet6LribaAVhbyou4dXSmahwd7a 3m1AFizfBm8JoDtqe8PLRKZBSGVdWkFqBKf4C73a+1ROpcLgfd+ec3cG3sdTg+jU3+pC MGj/69O2/0CqZPcUPfnYyUEl8Q3E03A6rFQCghywBso/6v02ggiZb0QGi70FcKLVSo1E GOzQ== X-Forwarded-Encrypted: i=1; AJvYcCWNQ8eyYwKeumuUPKT4neBkprpYkX8obNHACsWzX+Z2aQxI4abCw38fyu03DKqbjnsBM8/TMtYjWqVrBmQR@lists.postgresql.org X-Gm-Message-State: AOJu0YyNRYQG+/30bpYErUehMLM5TofSSHsXKECZT4xWsYuZsh4m1oSt UN4ARrinhkj3H84z/uuz/tRUH3mGmfqZWJHADvB2VYSfDVDYh3ZmkYdV+VNtrZ/N0gLWn3A9W/g gTaSxV5jf4FFIjrE/gwfpTIwlz/bGw30= X-Gm-Gg: AY/fxX61RXjGGTWd2xc0T9w+xwPHwInqXUe571DSC3VZefOP0ilPsZoyxO5AwtiV6wN ELcDSImXvchgVESwM9fFugguiXuaWM7h44pDQdBCYgRbGnIw1kH0hDHQ7FCqGtXDbuikp+9AYer x24Qws1EwAabEKbK/hsV5TnfXsRa0zN9M8M1FMQCEfBp3pBH5L9mnDtlgTmrQWQOT8LHq/YHxyK s2f3EY2q4ww1QSi6oukv0mKOxoHAlvXGwMxfoyOMyPBcXT4NFAM5UGQKGICdP/mF0bkJcKgy6J/ joEsgs2NE5MpwWVQx/ezu8zI4bBuhKH3Uoub9W8J X-Google-Smtp-Source: AGHT+IFLbWqdpQYVbA5BySPRJ9t7N0UUoKE56vd4Gy2ZdiKzKWhqvZVrsaCoayaQFpwGzy4F3w+GHTNeU3x24c8q0JM= X-Received: by 2002:a05:651c:210b:b0:37f:cf97:4957 with SMTP id 38308e7fff4ca-37fd091d1b8mr33734561fa.45.1765777706746; Sun, 14 Dec 2025 21:48:26 -0800 (PST) MIME-Version: 1.0 References: <5ABD7727-CD22-4112-A186-0E788EE78109@gmail.com> <23A24BFF-18A7-4FE9-AAFA-13E1AA207DD0@gmail.com> In-Reply-To: <23A24BFF-18A7-4FE9-AAFA-13E1AA207DD0@gmail.com> From: Amit Kapila Date: Mon, 15 Dec 2025 11:18:14 +0530 X-Gm-Features: AQt7F2pyjTfr68BToc_5MXeFY0_o79ASDgW4gxpnZKCX_B8osWLvO_VrAtmaX-k Message-ID: Subject: Re: Improve logical replication usability when tables lack primary keys To: Chao Li Cc: Dilip Kumar , Postgres 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, Dec 15, 2025 at 9:06=E2=80=AFAM Chao Li wr= ote: > > > On Dec 15, 2025, at 11:28, Dilip Kumar wrote: > > > > On Tue, Nov 11, 2025 at 6:11=E2=80=AFPM Chao Li wrote: > >> > >> Hi Amit, > >> > >> Thanks for asking. > >> > >>> On Nov 11, 2025, at 19:18, Amit Kapila wrot= e: > >>> > >>> On Mon, Nov 10, 2025 at 1:36=E2=80=AFPM Chao Li wrote: > >>>> > >>>> * BACKGROUND > >>>> > >>>> This requirement comes from several users operating large deployment= s, particularly in HIS (Hospital Information Systems). The situation can be= summarized as follows: > >>>> > >>>> - A central DB operations team maintains the main database and confi= gures 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 logic= al replication with `REPLICATION IDENTITY DEFAULT` requires a primary key, = such tables silently fail to replicate. > >>>> - The DB operations team must then spend significant effort identify= ing the affected tables and correcting them manually. > >>>> > >>> > >>> Can you share an example of how we silently fail to replicate? Won't > >>> in such cases UPDATE/DELETE will anyway raise an ERROR? > >>> > >> > >> Yes, UPDATE/DELETE will fail. That=E2=80=99s the easy case to expose t= he error. Actually my patch will allow the update/delete. > >> > >> However, some tables, like dictionary tables, they are important, but = don=E2=80=99t have much update/delete, they may silently fail to replicate. > > > > 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? > > > > Thanks for asking. When fallback to FULL, UPDATE/DELETE will be allowed i= n the publisher side. In my first email, attached v1 patch is a PoC that ha= s implemented the logic. > 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 think it should be done specific to tables that users want to replicate. 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. 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. --=20 With Regards, Amit Kapila.