Re: [PATCH] REPLICA IDENTITY USING INDEX accepts column with invalid NOT NULL

From: solai v <solai(dot)cdac(at)gmail(dot)com>
To: Ante Krešić <ante(at)tigerdata(dot)com>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] REPLICA IDENTITY USING INDEX accepts column with invalid NOT NULL
Date: 2026-06-18 09:21:19
Message-ID: CAF0whucta9opgHEU23iUaCY2Yk-dMzfSXXMcQ8VfO=D31keocA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I tested the patch on my current branch.
Before applying the patch i was able to reproduce the reported issue.
I created a table containing a NULL value, added a NOT NULL NOT VALID
constraint on the column, and created a unique index. PostgreSQL
accepted ALTER TABLE REPLICA IDENTITY USING INDEX even though the
underlying NOT NULL constraint had not been validated and the column
still contained NULL values. The command succeeded and relreplident
was set to i, confirming the behavior described in the report.

After applying the patch i repeated the same test.
PostgreSQL correctly rejected the operation with
ERROR: cannot use index "t_idx" as replica identity
DETAIL: The constraint "id_nn" on column "id" is marked NOT VALID.
HINT: You might need to validate it using ALTER TABLE ... VALIDATE CONSTRAINT.

This matches the expected behavior, since a column with an unvalidated
NOT NULL constraint cannot guarantee that all rows are non-null and
therefore should not be eligible for use as a replica identity.
I also ran the regression tests, and all tests passed successfully.

Regards,
Solai

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Matthias van de Meent 2026-06-18 09:27:28 Re: Unexpected behavior after OOM errors
Previous Message shveta malik 2026-06-18 09:16:51 Re: [PATCH] Preserve replication origin OIDs in pg_upgrade