Hi!
After the CLT feature committed [0] server nowl can deadlock if the
subscription has a conflict-log table and DROP SUBSCRIPTION races with
ALTER SUBSCRIPTION OWNER TO.




2026-12-02 16:04:43.070 UTC [588797] LOG:  process 588797 detected
deadlock while waiting for ShareLock on transaction 786 after 1000.094
ms
2026-12-02 16:04:43.070 UTC [588797] DETAIL:  Process holding the
lock: 589381. Wait queue: .
2026-12-02 16:04:43.070 UTC [588797] CONTEXT:  waiting for ShareLock
on transaction 786
while updating tuple (0,12) in relation "pg_subscription"
2026-12-02 16:04:43.070 UTC [588797] STATEMENT:  ALTER SUBSCRIPTION
clt_drop_race_1202 OWNER TO clt_drop_b_1202
2026-12-02 16:04:43.070 UTC [588797] ERROR:  deadlock detected
2026-12-02 16:04:43.070 UTC [588797] DETAIL:  Process 588797 waits for
ShareLock on transaction 786; blocked by process 589381.
Process 589381 waits for AccessExclusiveLock on relation 16506 of
database 5; blocked by process 588797.
Process 588797: ALTER SUBSCRIPTION clt_drop_race_1202 OWNER TO clt_drop_b_1202
Process 589381: DROP SUBSCRIPTION clt_drop_race_1202
2026-12-02 16:04:43.070 UTC [588797] HINT:  See server log for query details.
2026-12-02 16:04:43.070 UTC [588797] CONTEXT:  while updating tuple
(0,12) in relation "pg_subscription"
2026-12-02 16:04:43.070 UTC [588797] STATEMENT:  ALTER SUBSCRIPTION
clt_drop_race_1202 OWNER TO clt_drop_b_1202
2026-12-02 16:04:43.071 UTC [589381] LOG:  process 589381 acquired
AccessExclusiveLock on relation 16506 of database 5 after 16199.061 ms


ALTER OWNER locks the CLT before updating the pg_subscription tuple,
but DROP delete the subscription tuple before CLT lock. Attached
regression test covers the deadlock.

For the fix, I merely moved pg_subscription tuple deletion in
DropSubscription. I didn't find any core call sites who expect that
tuple deletion should go first, so done this way.


Without fix, test ends with

step s1_drop_subscription: <... completed>
step s2_alter_owner: <... completed>
ERROR:  deadlock detected

Test runner summary
-------------------
# ok 19        - multixact-aborted-updater
# diff -U3 expected/subscription_conflict_log_owner_drop.out
output_iso/results/subscription_conflict_log_owner_drop.out
# not ok 20    - subscription_conflict_log_owner_drop      435 ms
1..20
make: *** [check] Error 1




[0] 
https://git.postgresql.org/cgit/postgresql.git/commit/?id=6a0a66b3e7ac394c499708b790effea9a564ef0d

-- 
Best regards,
Kirill Reshke

Attachment: 0001-Drop-conflict-log-table-before-subscription-tuple.diff
Description: Binary data

Attachment: 0002-Test-subscription-conflict-log-owner-drop-with-injection-points.diff
Description: Binary data

Reply via email to