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 1v87FF-00D0Qk-E3 for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Oct 2025 01:21:01 +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 1v87FD-003Geh-2V for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Oct 2025 01:20:59 +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 1v87FC-003GeZ-La for pgsql-hackers@lists.postgresql.org; Mon, 13 Oct 2025 01:20:59 +0000 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v87FB-001QxH-2B for pgsql-hackers@postgresql.org; Mon, 13 Oct 2025 01:20:58 +0000 Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-856328df6e1so479556985a.0 for ; Sun, 12 Oct 2025 18:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760318456; x=1760923256; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=q4y1FvIz3SB8tspkYn0ge0SiKXGJh/3U3V8Cj0KD/CA=; b=cOdOtCVxWXFM9nQ5PZ3NlUhy7N8QTakPBVt/85g4l9mMTcXCKSctieGo5HbijtqAgE cb0DTwrkC0/Bcq7OoJnWe0eMdwlXMqEkHY7bo9eCC0XTdxC206dDnxhTER+OzQcZssBa 8o8Ndz7XRHrHCzwp9nvpomTFXEdUyvuYqdhT3XuXzDvD396MjVQliRjslVgiTcCcaBIJ yo3u973vbzfssd10XKpxUZSoxTqcV1tXUOZVeGgcQBdotrckkWPb+F3BfWJLuu58XYp/ PgLxDhF35M0NhC8pRO+TrAcw5F1dapaon51t/4MHGAv3YGkqK7wKY61QUZGkTnlJCL/j uHAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760318456; x=1760923256; h=content-transfer-encoding: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=q4y1FvIz3SB8tspkYn0ge0SiKXGJh/3U3V8Cj0KD/CA=; b=sannGqw350tCuRN8Y8Q/T9GVtRlknugyCoA2wYg1znM8dDzOraMjHd+F4AE+QBk80G Nwf7R/inDqGYqHUnV0TrlhmbG8vWTntt5/fT2wdS/PBITIpt1O9E6rsJacJ3BsIWxbpG I1LrdIlKnvyGow/CNvfKMczHGIOEWGXnFGO/8gq7oLJwxWiXPgdbX0e2O8ss2BHoVFVC o0IzOgUoUZZdWHqRyVkuhrriwhoS5OHuPgTrN9nklLJPOJyaLXVteU7nJ0AqUKKp2bKK aDOYpR4BnrfmK9hIH2ZRRqX3yhWtyMnsZURJrE/Xj/KXWI6UIyvIY4No2CVCuBYcIpM5 JbNg== X-Forwarded-Encrypted: i=1; AJvYcCVGNz11r0KlT8naKHl3/oK5kUNrT3OpcBrBkjHep3VPFZ/M+T0qDYkH8wyk5BRX05YZZowjMr7GQXw9W5A8@postgresql.org X-Gm-Message-State: AOJu0YwL97Yrn05Bm+yJ7Ckr8ScvpPrImRwh/YD1wF9KStD06zZM/WUi yecRF+yMKKKDofzqSitw3lGC3QjMg5RTAfCmlo6KQX8/qIXl7+VmnhwtbtJmi1qFKbGsj27YX4l tsO/l6ITtL6uYr7IRqbMZhdFHDhDXgt0= X-Gm-Gg: ASbGncsyNcgFClGt1fbDpKeKrAh5MECuUy9dRvHQL3Vmlt+GUwjxU408Wz+aR2yqRXu gNf2uGWJjzI+/K8jQrUtbWepU524W2I3Ty0hfWB30kw3nh8ZILUp47yX3UI0zJ5FLArKtYLZyFU E5hauXEXNrMNkbvW3RHotM72mHFJLcScF4a2yBBC2w6oePZJKyLs6ShhmGZnR1i/Tzo4b+jXMho zGs4QycQzFRgiRRcstHsqkwhsm0eWL+rilGJqBumZoRqaKK9HyYuci1r6U4yd4RKsutfog= X-Google-Smtp-Source: AGHT+IGNktdDPp0G/WUx+p0Bw1TN3hj8UZ769lt5/Nn4ShkHGQLub8jrd1NWfxP0DyIbsj8Ss7Plb/ioJL1IhHErALM= X-Received: by 2002:ac8:5fd3:0:b0:4dc:cb40:7078 with SMTP id d75a77b69052e-4e6eaccfec2mr262030531cf.19.1760318456038; Sun, 12 Oct 2025 18:20:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Mon, 13 Oct 2025 12:20:29 +1100 X-Gm-Features: AS18NWAeFnNcf8-UQfGqCSMBJCtenlR__WYJGHBz6cT-Tr4buv6lzoNhhZfoBwA 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" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Oct 13, 2025 at 9:28=E2=80=AFAM Peter Smith = wrote: > > Hi Iwata-San, > > Some v6 comments. > > =3D=3D=3D=3D=3D=3D > 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 databas= e 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 databa= se: > DROP DATABASE, > ALTER DATABASE RENAME TO, > ALTER DATABASE SET TABLESPACE, or > CREATE DATABASE. > Requires both BGWORKER_SHMEM_ACCESS and > BGWORKER_BACKEND_DATABASE_CONNECTION. > > > =3D=3D=3D=3D=3D=3D > 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. > > =3D=3D=3D=3D=3D=3D > 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 documen= tation. > > 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_CONNECTIO= N. > */ > > =3D=3D=3D=3D=3D=3D > src/test/modules/worker_spi/t/002_worker_terminate.pl > > +sub launch_bgworker > +{ > + my ($node, $database, $testcase, $allow_terminate) =3D @_; > + my $offset =3D -s $node->logfile; > > Would '$request_terminate' be a more correct name for the $allow_terminat= e var? > > =3D=3D=3D=3D=3D=3D > src/test/modules/worker_spi/worker_spi.c > > + bool allow_termination =3D PG_GETARG_BOOL(4); > > memset(&worker, 0, sizeof(worker)); > worker.bgw_flags =3D BGWORKER_SHMEM_ACCESS | > BGWORKER_BACKEND_DATABASE_CONNECTION; > + > + if (allow_termination) > + worker.bgw_flags |=3D BGWORKER_EXIT_AT_DATABASE_CHANGE; > + > > Would 'request_termination' be a more correct name for this new var? > There's another similar parameter name that I missed in the last post. See /src/test/modules/worker_spi/worker_spi--1.0.sql " allow_termination boolean DEFAULT false)" =3D=3D=3D=3D=3D=3D Kind Regards, Peter Smith. Fujitsu Australia.