Re: Publication DDL can race with a concurrent UPDATE

From: shveta malik <shveta(dot)malik(at)gmail(dot)com>
To: Zhijie Hou <houzhijie22(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>
Cc: "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, shveta malik <shveta(dot)malik(at)gmail(dot)com>
Subject: Re: Publication DDL can race with a concurrent UPDATE
Date: 2026-10-06 10:03:30
Message-ID: CAJpy0uCV3cnGxObcD3p0HaehLt95UUwu4t4XQuJBcm58O_UYBA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On v2, I see a deadlock because v2 locks the table first and then the
schema (a bottom-up approach). IIUC, this is the inverse order of
other commands, which take locks top-down (schema first, then table).
I think there could also be other such scenarios too that can
reproduce deadlock with v2. See this testcase:

CREATE SCHEMA test_schema;
CREATE TABLE test_schema.test_table (id int, val int);
INSERT INTO test_schema.test_table VALUES (1, 1);

Session A:
BEGIN;
--RowShareLock on table, just to make session B wait
SELECT * FROM test_schema.test_table FOR UPDATE;

Session B:
BEGIN;
-- Acquires AccessExclusiveLock on the schema.
-- Then blocks trying to lock the table, waiting on Session A.
DROP SCHEMA test_schema CASCADE;

Session A:
-- Upgrades table lock to RowExclusiveLock.
-- CheckCmdReplicaIdentity() then attempts to lock the schema.
UPDATE test_schema.test_table SET val = 2;

UPDATE fails with:
ERROR: deadlock detected
DETAIL: Process 20101 waits for RowExclusiveLock on object 16384 of
class 2615 of database 5; blocked by process 20115.
Process 20115 waits for AccessExclusiveLock on relation 16385 of
database 5; blocked by process 20101.
HINT: See server log for query details.

thanks
Shveta

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Sharma 2026-10-06 10:16:24 Re: Persist slot invalidations before publishing them
Previous Message Etsuro Fujita 2026-10-06 09:41:01 Re: Typo in version check in postgresAcquireSampleRowsFunc