Re: BUG #18988: DROP SUBSCRIPTION locks not-yet-accessed database - Mailing list pgsql-bugs

From vignesh C
Subject Re: BUG #18988: DROP SUBSCRIPTION locks not-yet-accessed database
Date
Msg-id CALDaNm2mGApdAEGudT0nn-bMAqm-Gy9JvccpX0K1DAAYUS3iSA@mail.gmail.com
Whole thread Raw
In response to RE: BUG #18988: DROP SUBSCRIPTION locks not-yet-accessed database  ("Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>)
Responses Re: BUG #18988: DROP SUBSCRIPTION locks not-yet-accessed database
List pgsql-bugs
On Thu, 31 Jul 2025 at 14:34, Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
>
> Dear Vignesh, Dilip,
>
> I found another corner case:
>
> ```
> postgres=# CREATE SUBSCRIPTION sub CONNECTION 'dbname=db1 user=postgres port=5431' PUBLICATION pub1 WITH
(connect=false,slot_name=sub);
 
> WARNING:  subscription was created, but is not connected
> HINT:  To initiate replication, you must manually create the replication slot, enable the subscription, and refresh
thesubscription.
 
> CREATE SUBSCRIPTION
> postgres=# DROP SUBSCRIPTION sub ;
> ... (won't return)
> ```
>
> Because still can explicitly specify the slot_name while creating the subscription.
> Another pattern is to run ALTER SUBSCRIPTION SET (slot_name) command after the
> CREATE SUBSCRIPTION WITH (connect=false);.
>
> Should we fix the case? If so, how?

An alternative approach would be to acquire an AccessShareLock on
pg_subscription, and then explicitly lock the target subscription row
using LockSharedObject with AccessExclusiveLock while dropping the
subscription. On the launcher side, before starting a worker, it
should similarly acquire an AccessExclusiveLock on the corresponding
subscription row using LockSharedObject. Once the lock is acquired, it
must revalidate that the subscription still exists, to prevent race
conditions with concurrent drops, before proceeding to start the
worker.

Thoughts?

Regards,
Vignesh



pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #19006: Assert(BufferIsPinned) in BufferGetBlockNumber() is triggered for forwarded buffer
Next
From: Dilip Kumar
Date:
Subject: Re: BUG #18988: DROP SUBSCRIPTION locks not-yet-accessed database