[PATCH] Disallow column lists on tables with REPLICA IDENTITY FULL when publishing updates/deletes

From: Mohit Kumar <mohit(dot)bash(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH] Disallow column lists on tables with REPLICA IDENTITY FULL when publishing updates/deletes
Date: 2026-10-24 20:41:14
Message-ID: CAGQj2Cr8wu32S_Bs6pgfXRHHq6V4ebOCL2nTdYiYUtW8wyinmw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

I would like to propose a patch to catch an invalid publication
configuration
at DDL time rather than deferring the failure to runtime DML.

Problem:
Currently, CREATE PUBLICATION and ALTER PUBLICATION allow specifying a
column
list on tables that have REPLICA IDENTITY FULL, even when the
publication publishes
UPDATE and DELETE operations (the default).

For example:

CREATE TABLE mytab (id int, val text, extra text);
ALTER TABLE mytab REPLICA IDENTITY FULL;

-- 1. This succeeds silently with no warning or error:
CREATE PUBLICATION mypub FOR TABLE mytab (id, val);

-- 2. Inserts work fine:
INSERT INTO mytab VALUES (1, 'hello', 'world');

-- 3. Any subsequent UPDATE or DELETE fails in production:
UPDATE mytab SET val = 'updated' WHERE id = 1;
-- ERROR: cannot update table "mytab"
-- DETAIL: Column list used by the publication does not cover the
replica identity.

This recently caused an unexpected production outage for us: the schema
migration
succeeded cleanly without error in CI/CD, but application web traffic
immediately
began failing on subsequent UPDATE and DELETE operations.

Proposed Solution:
Because REPLICA IDENTITY FULL requires the entire row to identify
tuples on the
subscriber, a column list on such a table can never work for updates or
deletes.

The attached patch adds early validation in
CheckPubRelationColumnList() and
AlterPublicationOptions():
1. During CREATE PUBLICATION and ALTER PUBLICATION ... ADD/SET TABLE,
if the
publication publishes UPDATE or DELETE and the table has REPLICA
IDENTITY
FULL, an immediate error is raised:
"ERROR: cannot use column list for relation "..." in publication
"...""
"DETAIL: Column lists cannot be specified for tables with REPLICA
IDENTITY FULL
when publishing updates or deletes."
"HINT: Either change the table's REPLICA IDENTITY or configure the
publication
to publish only 'insert'."
2. During ALTER PUBLICATION ... SET (publish = ...), if a publication
already
contains a table with a column list and REPLICA IDENTITY FULL,
adding 'update'
or 'delete' to publish actions is rejected.
3. Insert-only publications (e.g. publish = 'insert') remain allowed and
unaffected.

Regression tests in publication.sql and publication.out have been
updated,
and all regression tests pass.

Looking forward to your feedback.

Thanks,
Mohit

Attachment Content-Type Size
0001-Disallow-column-lists-on-tables-with-REPLICA-IDENTIT.patch text/x-patch 12.0 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Tom Lane 2026-10-24 20:09:10 Re: Self-join elimination discards differing row lock wait policies