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.94.2) (envelope-from ) id 1vAhb1-005AtD-Sk for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Oct 2025 04:34:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vAha1-00E8o7-Hu for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Oct 2025 04:33:08 +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.94.2) (envelope-from ) id 1vAha0-00E8nz-It for pgsql-hackers@lists.postgresql.org; Mon, 20 Oct 2025 04:33:08 +0000 Received: from fout-a1-smtp.messagingengine.com ([103.168.172.144]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vAhZx-002isV-2D for pgsql-hackers@postgresql.org; Mon, 20 Oct 2025 04:33:06 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 60397EC00B3; Mon, 20 Oct 2025 00:33:04 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Mon, 20 Oct 2025 00:33:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1760934784; x=1761021184; bh=HSLVkFwHCo r6j8sl3jtHBF+xu6EDZu39kvOMr39ncRw=; b=f+Glnc4ClVulv1BrKfi0mVnY2Q FflthakKnCBUbriTlHBzPHAI3tMalOevmKQZJV+sIgQ8nr31Hcg3JVd/KkwA4COm J4jATT1TL9MwoaiIsoUzhroav6jmBupBsBGFJJ0wDK0qcVbNmZhkPiQhJNuiHolS Y1uay8CEDHyowmOHc/ijqpDc0QXosZpK+zuNfGv09WhsPtyHDhlwjeERiahSJsQ6 711t2vYpRZaiJwK+kb0f6ys4dsf+fLDf1nVqKP+DVSM4PCUI4vcuL28RtHNwBfmm Ou5FCq0Qd3X0yV048vNuztRJjGX5QIsOG5ugjNLzXfq6hCcKrp8SruqNo4jw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1760934784; x=1761021184; bh=HSLVkFwHCor6j8sl3jtHBF+xu6EDZu39kvO Mr39ncRw=; b=IG8QsY3x+tT2zP+lVY+wuSGivkAu+fq3Q9F/dRhXS6jXb1RP1n9 LdxJ92COtNSTaq6Fk9f83B1R1RUWV3+ZGgaOxpGgG+BGyufGZDogp2RsavbNiuCU V365Eecnn+tsDDfTslwSpya+Kxd+d68eUCrh/OJXKUi3o1xc9SKlscrirDxLmS8G 9wyP3ZxoI0t0vN1BLUvd+PnN87mR5FMKqGrAmfNf03uJwy+X0VSHpxyAnpqUHFoR NLR3r9cLfbHR3AXARqSI5iQhaT4ysrldS/tA8RQZQm6oR+p7yOBJxd/3R8RSS1yK RsFE94wqPF3XHdYqU0oylV8+793Sw75gGCA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddufeeikeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeggeeg fffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidp nhgspghrtghpthhtohephedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepshhmih hthhhpsgdvvdehtdesghhmrghilhdrtghomhdprhgtphhtthhopehifigrthgrrdgrhigr sehfuhhjihhtshhurdgtohhmpdhrtghpthhtoheplhhirdgvvhgrnhdrtghhrghosehgmh grihhlrdgtohhmpdhrtghpthhtohepkhhurhhouggrrdhhrgihrghtohesfhhujhhithhs uhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvsh hqlhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Oct 2025 00:33:01 -0400 (EDT) Date: Mon, 20 Oct 2025 13:32:44 +0900 From: Michael Paquier To: Peter Smith Cc: "Aya Iwata (Fujitsu)" , Chao Li , "Hayato Kuroda (Fujitsu)" , pgsql-hackers Subject: Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="beWy2yPeXhF4fpvW" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --beWy2yPeXhF4fpvW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Oct 20, 2025 at 01:01:31PM +1100, Peter Smith wrote: > Some comments for the latest v8 patch. The comments of Peter apply to comments and parameters. I am not going down to these details in this message, these can be infinitely tuned. The injection point integration looks correct. You are checking the compile flag and if the extension is available in the installation path, which should be enough. + if (IS_INJECTION_POINT_ATTACHED("reduce-ncounts")) + ntries = 10; 1s is much faster than the default of 5s, still I am wondering if this cannot be brought down a bit more. Dropping the worker still around after the first test with CREATE DATABASE works here. +# Confirm a background worker is still running +$node->safe_psql( + "postgres", qq( + SELECT count(1) FROM pg_stat_activity + WHERE backend_type = 'worker_spi dynamic';)); This does not check that the worker that does not have the flag set is still running: you are not feeding the output of this query to an is() test. + is($result, 't', "dynamic bgworker launched"); In launch_bgworker(), this uses the same test description for all the callers of this subroutine. Let's prefix it with $testcase. +void +TerminateBgWorkersByDbOid(Oid oid) FWIW, while reading this code, I was wondering about one improvement that could show benefits for more extension code than only what we are discussing here because external code has no access to BackgroundWorkerSlot while holding the LWLock BackgroundWorkerLock in a single loop, by rewriting this new routine with something like that: void TerminateBackgroundWorkerMatchin( bool (*do_terminate) (int pid, BackgroundWorker *, Datum)) Then the per-database termination would be a custom routine, defined also in bgworker.c. Other extension code could define their own filtering callback routine. Just an idea in passing, to let extension code take more actions on bgworker slots in use-based on a PGPROC entry, like a role ID for example, or it could be a different factor. Feel free to dislike such a funky idea if you do not like it and say so, of course. -- Michael --beWy2yPeXhF4fpvW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmj1u2wACgkQnvQgOdby QH2MmQ/9Hv1iE5oAX7FenLCG+s6Fxs1Lp46fIsRWR40ATb/fInka47jGKGdccpwj GOqt4rNhRnDhBlkn4hXs+Y8tWbNuANTWSD4yPvq9NaYT5LywQXewcHNlDAFOzLbI 6am7wYFi6UioWKjRgrK+N3w2BL7BEf8OjpnfRx1XJVtOi+KjWxe3ckxpWWGN7uUh tpwH1hJOW2igFXyZDh9RYkwQzUxUlDtYd8joXcPXUw86PKLP012ULm16wZZrDfS5 AcBrlmAjtjCI7dQzZbKQ0MzivQ/K4ice6Y3+89FU+V117aBAwmZfvxIfPILNRIuB EaKY38qLuimCnXGFB1nlS3HKSjzht08wLOR9qtVa4sEIjumUdn2yxEGswXkZNRUv BP5y/WoOYXoRJKLSCm4c5y5kMAVQUFyGiZDkVxeKvkWGmbx2yyhOCKT82mckW3Yt jGNd8V5A/1dQZdHjqKLBaN5Dvt38+cylPbw1N8LYkUWr/F0hfqN+PPHHtef2dx62 Tf1O4pnUeioAtxDjnw+BlzeewQE5caC/TMIGJw4q4mWI2+2Gfl3jW4gus+xv1djn 2IPrvPC8gvmVosVjTjoSqt5AjgBYZcDexccIGdjlqCY99SbuToLZYP4pFxSqcLdg sDGi/WNzDMzn7+9F2SWgEyNcG/F0/WWGTABrTzPIkZ39LMvQVno= =0b4E -----END PGP SIGNATURE----- --beWy2yPeXhF4fpvW--