Re: Logical replication commits duplicates in DEFERRABLE unique indexes

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, Michael Malis <malis(at)pgrust(dot)com>
Subject: Re: Logical replication commits duplicates in DEFERRABLE unique indexes
Date: 2026-11-23 22:49:10
Message-ID: CAN4CZFMLMA3t2gEbfOf15idBtoNcbAqDVE-HkkFQuxS6kwFX4w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello

This can stall the apply worker:

-- subscriber: CREATE ROLE app; CREATE TABLE ledger (id int PRIMARY
KEY DEFERRABLE INITIALLY DEFERRED, v text);
-- ALTER TABLE ledger OWNER TO app; subscription owned
by superuser, run_as_owner = false
-- publisher (REPLICA IDENTITY FULL), rows 1..3:
UPDATE ledger SET id = id + 1;
-- patched subscriber stays {1,2,3}, retried forever:
ERROR: cannot fire deferred trigger within security-restricted operation
-- master: {2,3,4}

Also, attach partition bypasses the check:

CREATE TABLE pt2 (id int, v int, PRIMARY KEY (id) DEFERRABLE INITIALLY
IMMEDIATE);
ALTER TABLE pt ATTACH PARTITION pt2 FOR VALUES FROM (100) TO (200);
-- pt is subscribed

And

+ if (localrelkind == RELKIND_PARTITIONED_TABLE)
+ relids = find_all_inheritors(relid, AccessShareLock, NULL);
...
+ table_close(rel, AccessShareLock);

find_all_inheritors() doesn't lock the root itself, this either
results in a warning or unlocks a table the caller locked.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-11-23 22:56:44 Re: BUG #19761: btree_gist: "cannot subtract infinite dates" when inserting 'infinity' into a GiST index on date
Previous Message Zsolt Parragi 2026-11-23 22:16:37 Re: Timing issue in pg_basebackup