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 1v84Yz-00CI8U-J0 for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Oct 2025 22:29:13 +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 1v84Yx-002abX-88 for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Oct 2025 22:29:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v84Yw-002abP-Qv for pgsql-hackers@lists.postgresql.org; Sun, 12 Oct 2025 22:29:11 +0000 Received: from mail-qk1-x734.google.com ([2607:f8b0:4864:20::734]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v84Yv-001oll-1m for pgsql-hackers@postgresql.org; Sun, 12 Oct 2025 22:29:11 +0000 Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-85c66a8a462so667892685a.0 for ; Sun, 12 Oct 2025 15:29:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760308147; x=1760912947; 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=EQ1V95n9/oCAd/Jl785XUigtA+DfST9ZHa4W49q+cSM=; b=H1PkARHR36uKRsYhE6V0Yol+H2xp8CvlDvyrjaSX4gS2knNL/bTCmzhcJNHhusQtIE reT2VidOzJJ3x+sg49VjIcpmTSYCKueRPgH2WIQH3v4ro5Q9069KD2u86328IfTjkMuS k1GUNmM7ZJ/dr2ze6K6qGH/T8oIy6YTFruq9Q3GDcHzHv7zVdO1Hzhr80Znd6vrovyKU jITrFSp5yiPhMM4UeSrNtX/zfa5ALc5kAc8kGYZXfigtPS8uVbJ3Tdr7p5GdUATnZuqQ IhmToD+WL5nO6Lxu6/LvVAku+M4daXtM/uWtxblGnceUdicKJFlFwP00oYBC/z3InQWB xzbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760308147; x=1760912947; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EQ1V95n9/oCAd/Jl785XUigtA+DfST9ZHa4W49q+cSM=; b=oOU8iatUNARNd+K8hd3dYCVuEfB/tSuYVxSMDsI8VPUgqd1B1g+u9MDrsek/0GEiSI CtRYzQGJfJwRSjxgnzeBeDoPxy6Av/bvGGX1+5t1JFKFD5ye3q+h+9txZ7IduNERCqcX J9Q4LwmyVbMaiSBvRl6NLhZp/yZ39mPmviO0BJ0JAC7uj7AyYXYSxoZixrcUtU51bDIr nzJWeg+zOSb4Sy6Jm+8dwZpoWIZfX69VS7AGH0JbsijkwLo63UCR7O1wH9O85MSu7z0S C+fRCQ76hnl79T7ed+kUd22aUwVQEu1la6QZt3T+ue8QYBRHUE5hUhdd3dXnBP8Zt6CV rbzg== X-Forwarded-Encrypted: i=1; AJvYcCWmbWt9ZpWiggA63lBTjrOO9Mlu0nxpwTiUnASdK6Q2CHBYF0MtwrMz5teP/93hcG6G925QPHV9KiPuwKMj@postgresql.org X-Gm-Message-State: AOJu0YxbNm0Pju8KrnPBeOYOX0lwnUbJZORut3NAFZx2euNtGBqDoCsj NVqasAxc3KKRy/tMMwdiLTokb+Fl5rKvTzM2xRO5yY+J2NqgDCOO4e22lw/eIL919FBfFvo9w/Y tXzeXin9BgwAUabO4VCTj0mUT/ccFPVI= X-Gm-Gg: ASbGncuqkclsRk8LzVwOxoQvAnHmimvaNkY3FVgCBC83o/IIfBs8n1gf2g/4TsydGiI UAAq7IpnmcagBZmgzEqCY7sDPLQkBwY/Um73xI1dp9xvMw9gm5jRfgf791TocjubHcNi3cvvd0l 6we3bfAR4U3RIIaSWdquaUWMeh4xJQgxqi8m3+pyySRZNvZduj3ErNvmeoasJC449HCWgSKiKx6 B1ODpDYAvyWWClx2QA61lngJOOYdJVHlki6/+afqUIIJbDQQG/jJq/RnJnjO0iJAcQDcG4= X-Google-Smtp-Source: AGHT+IGQlLI+zshYJ9BE24+M2Q7/y/2sP9jSQPNSogpYkSL/WYOXtRq3/f30+GoPEzJs8AknfKjulvq0ivJX9ENzUAQ= X-Received: by 2002:ac8:5a54:0:b0:4e4:d480:ef66 with SMTP id d75a77b69052e-4e6eaceb3dcmr235137381cf.34.1760308147372; Sun, 12 Oct 2025 15:29:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Mon, 13 Oct 2025 09:28:40 +1100 X-Gm-Features: AS18NWC8cLK29tal4eoATlBPWoC35QGZqK-UyCCLFtIoAh2K40FAXO7t0tkC9ww Message-ID: Subject: Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE To: "Aya Iwata (Fujitsu)" Cc: Chao Li , "Hayato Kuroda (Fujitsu)" , Michael Paquier , pgsql-hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Iwata-San, Some v6 comments. ====== doc/src/sgml/bgworker.sgml 1. + + BGWORKER_EXIT_AT_DATABASE_CHANGE + Requests termination of the background worker when its connected database + is dropped, renamed, or moved to a different tablespace. + In these cases, the postmaster will send a termination signal to the + background worker when any of the following commands are executed: + DROP DATABASE, + ALTER DATABASE RENAME TO, + ALTER DATABASE SET TABLESPACE, or + CREATE DATABASE (when the worker is connected to the + template database). + This flag requires both BGWORKER_SHMEM_ACCESS and + BGWORKER_BACKEND_DATABASE_CONNECTION. + IMO, below is an improved wording for this: BGWORKER_EXIT_AT_DATABASE_CHANGE Requests termination of the background worker when its connected database is dropped, renamed, moved to a different tablespace, or used as a template for CREATE DATABASE. Specifically, the postmaster sends a termination signal when any of these commands affect the worker's database: DROP DATABASE, ALTER DATABASE RENAME TO, ALTER DATABASE SET TABLESPACE, or CREATE DATABASE. Requires both BGWORKER_SHMEM_ACCESS and BGWORKER_BACKEND_DATABASE_CONNECTION. ====== src/backend/postmaster/bgworker.c + + +/* + * Terminate all background workers connected to the given database, if they + * had requested it. + */ +void +TerminateBackgroundWorkersByOid(Oid databaseId) Only 1 blank line is needed here. ====== src/include/postmaster/bgworker.h +/* + * Exit the bgworker when its database is dropped, renamed, or moved. + * No-op if BGWORKER_BACKEND_DATABASE_CONNECTION is not specified. + */ +#define BGWORKER_EXIT_AT_DATABASE_CHANGE 0x0004 + That double-negative comment seems awkward. IMO, positive statements are clearer. Also, do you think you should mention BGWORKER_SHMEM_ACCESS, or was that deliberately omitted because BGWORKER_BACKEND_DATABASE_CONNECTION requires that? e.g. The suggested comment below is more closely aligned with the documentation. SUGGESTION: /* * Exit the bgworker when its database is dropped, renamed, moved to a * different tablespace, or used as a template for CREATE DATABASE. * Requires BGWORKER_SHMEM_ACCESS and BGWORKER_BACKEND_DATABASE_CONNECTION. */ ====== src/test/modules/worker_spi/t/002_worker_terminate.pl +sub launch_bgworker +{ + my ($node, $database, $testcase, $allow_terminate) = @_; + my $offset = -s $node->logfile; Would '$request_terminate' be a more correct name for the $allow_terminate var? ====== src/test/modules/worker_spi/worker_spi.c + bool allow_termination = PG_GETARG_BOOL(4); memset(&worker, 0, sizeof(worker)); worker.bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION; + + if (allow_termination) + worker.bgw_flags |= BGWORKER_EXIT_AT_DATABASE_CHANGE; + Would 'request_termination' be a more correct name for this new var? ====== Kind Regards, Peter Smith. Fujitsu Australia