| From: | Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com> |
|---|---|
| To: | Kirill Reshke <reshkekirill(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: DROP SUBSCRIPTION deadlock with ALTER SUBSCRIPTION OWNER TO |
| Date: | 2026-12-03 06:43:47 |
| Message-ID: | CANhcyEXKn6gH+5TZNvho=+QNJyGs8Vs+hJcabR9Kn=5RyAdrkg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, 3 Dec 2026 at 02:39, Kirill Reshke <reshkekirill(at)gmail(dot)com> wrote:
>
> 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
>
Hi Kirill,
Thanks for the report. I was able to reproduce the deadlock, with the
steps provided by you.
I reviewed 0001 patch and found an issue, that the changes introduced
by 0001 can leave CLT orphaned.
Steps to reproduce:
Create logical replication set up. Subscription is created with
(conflict_log_destination = log).
Create two psql sessions, S1 and S2, for subscription node.
S1: DROP SUBSCRIPTION sub1; (Pause the session after
'subconflictlogrelid = form->subconflictlogrelid' in DropSubscription
function using GDB)
S2: ALTER SUBSCRIPTION sub1 SET (conflict_log_destination = table);
S1: continue the Drop subscription command.
Alter Subscription ... SET command creates the conflict log table for
subscription sub1. But after the DROP SUBSCRIPTION command is resumed,
it is successful and drops the subscription 'sub1' but the
corresponding Conflict log table is not cleaned up.
On HEAD, after DROP SUBSCRIPTION Command is resumed, it throws a error:
postgres=# DROP SUBSCRIPTION sub1;
ERROR: tuple concurrently updated
Thanks,
Shlok Kyal
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-12-03 07:04:10 | Re: [PATCH v2] Reuse slot helpers in pg_get_replication_slots and slot copy |
| Previous Message | solai v | 2026-12-03 06:33:41 | Re: [PATCH] Improve tab completion for CREATE DOMAIN without AS |