Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVtXI-009VQO-0q for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Dec 2025 15:33:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVtXH-00DxS8-0k for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Dec 2025 15:33:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVtXG-00DxQG-2W for pgsql-hackers@lists.postgresql.org; Wed, 17 Dec 2025 15:33:55 +0000 Received: from mail-yw1-x112c.google.com ([2607:f8b0:4864:20::112c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vVtXG-001AaX-04 for pgsql-hackers@postgresql.org; Wed, 17 Dec 2025 15:33:54 +0000 Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-78c696717dbso54915437b3.1 for ; Wed, 17 Dec 2025 07:33:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765985633; x=1766590433; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nvOywr9mwNqffV1Smm32DcZPq2+6N47seuY3Vckfk3k=; b=Kfnbi+cdqjaD/IIDX8MMpKeR7YxWw5mih8za4DvcH1v2ULDpmhveD9azaVYXDJELbT CAdvMC63UBKjw/NEJiRZeGj7J+0NOLEUuScpeVfNQdTTPrEgVIclKvza7fsNAvUC7zvB IjPXHItqYVM81bYa2D0rKrqdVMthehZLTbHotpYXYt1n5MTXvzqhxXuFMH+g2YP6OI9G bf4/hYPICVBaxfCKGQlXGf7xELMg05feHSpitD1ELbUMZmJZkL6e6BjllpNIJ7+fSPYm zU2V7qSYAxk7YPn+JYsa2N1XETAJo2aONwjvVjXBcJbZxT0+oI6f2vo1cZuWduwB6+vY n2Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765985633; x=1766590433; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nvOywr9mwNqffV1Smm32DcZPq2+6N47seuY3Vckfk3k=; b=apI0qJCnprQxjgQLM3cpofXh7BnwmgQqi3ULxo/4G2W7Mrt6dL5HrcYI2hwh5QVmOy Ak4i7bE9zmDE+Jukdej2rfqmZGh8QKmdJu4Eqhgf2Ro0LAX5GTJJMctBoAXAwdxF8kw9 PDOPKLHZklWKR410YU0Dz2BlFBkFLFNEpzrRAQ76SbDrjppce++clndTraeK9f1HXHG8 O1SFhHhr4E01R8k8Okw6hj4OhnTEEm8hGogarXRffzWcBoyALEltnqqeNw8SgN8w8124 qDL4B48sdb8nINxdJd6ZbmGyKASaUwWCTyipm99/mnvuw3FKe6eB2aS0NOUI+Y/GsZrW bNRA== X-Forwarded-Encrypted: i=1; AJvYcCU5VRuNg5Zb13x2Peh9YHRSFjzRqJOFDuseY5Cqm6aw3JY76p9SukZ05oknpap2Ev9gMyqxqkrmb3xpuhGz@postgresql.org X-Gm-Message-State: AOJu0Yy8mDPPAYS6LbDo4RebxclFRTlzpXyNJDkm2vqgcVDZ1TYqgSG1 CRr8uGirCYWAglyXr9+8bGNhj0nDpvkUcjqlbxbOS+WPqRvFxd81/tzcK3SDEWSLvYFu2lLgNxF CNi9cFUQauHheeeYf2ydXHg5glSlL6Rw= X-Gm-Gg: AY/fxX4m9c85kLGe8HjtAGjuYsCRihFtdqZ+IDB19gwCJ8ZbVKQtLVbaWmxjkPdotc3 cmdxZtgIhG8yfSO+thBSDerPfG9wHUt99bkYgbXjNsL6yr3zpzUkuJ5Wyh2K9CinaQazDRMicG5 pK6shNlMm86vA9FZC9mVJGOmNkkFkRC7iT6glOqB6TlVJ4owO/56eHNM7VU5kbCaeTDlUyz8KJh i60fLgOPbsz1W1tjTfIoZeMTVXFjhSfc9qDEaNBUgW3+h/A6Ex97hJYaMypYJGmtiuOSoaofWzz fZdNE0V+68xzgLKX92dqE+33T5vmtf8OuGE291pOKeQk1fIK1iLKVaebuzt83pwUyLhKwORxZOF KCVA9T+ruqSPb5g== X-Google-Smtp-Source: AGHT+IF/JoaUjB9oYZiuiofQ/hs4K0/1MDnAyfDlt6QZWkPE48rOHjSMQvC3JP5/P153YLD9enckp2B2lF3oEqwTm2o= X-Received: by 2002:a05:690c:4443:b0:787:fec5:7072 with SMTP id 00721157ae682-78e66e5026fmr153131447b3.57.1765985632979; Wed, 17 Dec 2025 07:33:52 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Pavel Stehule Date: Wed, 17 Dec 2025 16:33:16 +0100 X-Gm-Features: AQt7F2o5hoV6V35yj9uHImRYx7E83hzj88PXGiMxTLEg79A6RPwOZ-GWcB9p1Wc Message-ID: Subject: Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE To: "Aya Iwata (Fujitsu)" Cc: Michael Paquier , Peter Smith , Chao Li , "Hayato Kuroda (Fujitsu)" , pgsql-hackers Content-Type: multipart/alternative; boundary="00000000000055102a0646279267" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000055102a0646279267 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi st 17. 12. 2025 v 14:31 odes=C3=ADlatel Aya Iwata (Fujitsu) < iwata.aya@fujitsu.com> napsal: > Hi Pavel-san, > > >> So maybe there should be ALTER DATABASE ... RENAME ... FORCE - or if > FORCE can terminare all workers (without special FLAG) ? > > > > For the proposed feature, we've added a flag allowing each extension > developer to decide whether to terminate it via DROP/ALTER DATABASE. > > Adding a FORCE option to ALTER to let database definition modifiers > decide whether to force termination of background workers might be better > discussed in a separate thread. > > > > When I thought about it - there can be a second alternative. > > > > Introduce a pair of flags BGWORKER_INTERRUPTABLE and BGWORKER_PROTECTED > (the names can be enhanced or changed). BGWORKER_INTERRUPTABLE can be > default. > > ALTER DATABASE RENAME and related commands can stop any non protected > workers. ALTER DATABASE RENAME FORCE can stop any workers (including > protected). > > I can't image any use cases for BGWORKER_PROTECTED. Do you have any idea? > Also, I think the parameter settings might get a complicated. > If we start discussing the "FORCE" option, it is better to think about > this parameter. > > > Is there any reason why BGWORKER_INTERRUPTABLE cannot be default? > Probably nobody would block some possibly common operations on database > level without strong reason. > > As Michael-san mentioned in a previous email, this behavior has remained > unchanged since bgworkers were introduced in v9.3. > I don't see a compelling reason to alter it now. Additionally, this > specification can be modified later. > I understand the request for unchanging behaviour - but I am not sure if this concept is really helpful - or if the naming is best. I am afraid so this feature without changing the workers code is useless (and maybe it is wanted). Any worker should be interruptable by sigterm. And then the name BGWORKER_INTERRUPTABLE is little bit vague. Maybe some like BGWORKER_CAREFREE_INTERRUPTABLE can be better (or some like this - maybe BGWORKER_CANCELABLE)? This can be a signal from bgworker's authors - it is ok to kill the worker anytime when it is necessary. Some workers can have the flag BGW_NEVER_RESTART - cannot be used as signal so this worker is protected, and others can be terminated safely, because they will be restarted after 60 seconds? Regards Pavel > > Best Regards, > Aya Iwata > --00000000000055102a0646279267 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

st 17. 12. 2025 v=C2=A014:31 = odes=C3=ADlatel Aya Iwata (Fujitsu) <iwata.aya@fujitsu.com> napsal:
Hi Pavel-san,

>> So maybe there should be ALTER DATABASE ... RENAME ... FORCE - or = if FORCE can terminare all workers (without special FLAG) ?
>
> For the proposed feature, we've added a flag allowing each extensi= on developer to decide whether to terminate it via DROP/ALTER DATABASE.
> Adding a FORCE option to ALTER to let database definition modifiers de= cide whether to force termination of background workers might be better dis= cussed in a separate thread.
>
> When I thought about it - there can be a second alternative.
>
> Introduce a pair of flags BGWORKER_INTERRUPTABLE and BGWORKER_PROTECTE= D (the names can be enhanced or changed). BGWORKER_INTERRUPTABLE can be def= ault.
> ALTER DATABASE RENAME and related commands can stop any non protected = workers. ALTER DATABASE RENAME FORCE can stop any workers (including protec= ted).

I can't image any use cases for BGWORKER_PROTECTED. Do you have any ide= a?
Also, I think the parameter settings might get a complicated.
If we start discussing the "FORCE" option, it is better to think = about this parameter.

> Is there any reason why BGWORKER_INTERRUPTABLE cannot be default? Prob= ably nobody would block some possibly common operations on database level w= ithout strong reason.

As Michael-san mentioned in a previous email, this behavior has remained un= changed since bgworkers were introduced in v9.3.
I don't see a compelling reason to alter it now.=C2=A0 Additionally, th= is specification can be modified later.

I understand the request for unchanging behaviour - but I am not sure if t= his concept is really helpful - or if the naming is best. I am afraid so th= is feature without changing the workers code is useless (and maybe it is wa= nted).

Any worker should be=C2=A0interruptable=C2= =A0by sigterm. And then the name=C2=A0BGWORKER_INTERRUPTABLE is little bit = vague. Maybe some like=C2=A0BGWORKER_CAREFREE_INTERRUPTABLE can be better (= or some like this - maybe BGWORKER_CANCELABLE)? This can be a signal from b= gworker's authors - it is ok to kill the=C2=A0worker anytime when it is= necessary.=C2=A0

Some workers can have the flag B= GW_NEVER_RESTART - cannot be used as signal so this worker is protected, an= d others can be terminated safely, because they will be restarted after 60 = seconds?

Regards

Pavel
=C2=A0

Best Regards,
Aya Iwata
--00000000000055102a0646279267--