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 1v5y8x-00Eleh-CD for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Oct 2025 03:13:39 +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 1v5y7v-00Cty2-KA for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Oct 2025 03:12:36 +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 1v5y7v-00CtxM-8c for pgsql-hackers@lists.postgresql.org; Tue, 07 Oct 2025 03:12:36 +0000 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v5y7t-000Q8A-0P for pgsql-hackers@postgresql.org; Tue, 07 Oct 2025 03:12:34 +0000 Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-4d9f38478e0so56932171cf.1 for ; Mon, 06 Oct 2025 20:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759806753; x=1760411553; 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=a2/GxO6CIAhB5euyxRxhcu4uatScor3gNLLpw3024po=; b=VtftLj+NSYq+afkreYSdeZ3lSVxBwQeJIfCNqyhvBI1qvrTLbIIwgwz+qjfNwzGOga Vv2cRIEOnLXTPolMYpM5IRfrCiGb8re0gTBhlkizEV0gYcEk6quEmSLac8zANLPadpZC SKGNs/041IF1GKy6H50ZQMsoHnYJh35I9uYpoU7CjaIWj8I8wWeX7K/Oni1I4ce2uqVT 4Wio5GmGGd9Xn2I+Ixts87WLfAd2vouus4jiAkzpXibc9DadnXDJupdXcF9awJz9nud0 +JDBBnSDehEfHFQ0+PDcSHai8pWOkd2uC64d0BK9B4CmqMk44OdNhiEwA58ERlRcv7xc PNgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759806753; x=1760411553; 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=a2/GxO6CIAhB5euyxRxhcu4uatScor3gNLLpw3024po=; b=CHhSIqtvmwp2BcmG00ZIPiW9Nx07B0Bz6EEydgpZJQwhtEZDWUcUlFBGjYouGP/Azu mSChecuWgQjKCH2K4irQ4YV6hr86h+XGDaLgm+IX+QpZ4SbXsgLU5cZ+eZh9REYMbEq4 Bqg0hARTNe2VckMEOV3LHqDcVg4jUcqK21zo5w2pEM8CouxqB0/mlazl56OOTl1nJH7h lcx49kczplrkKPAPeHOo43XFY4COht3s9TJhRAwUzhh9fLwoCKYlqu9osjpfQzuMxTq+ PoLRbKWLIDZPXeZgIOBE+W+tNQYhLbpMlPcnzUpi9VryVD/4Cq8ATwLfgvtGfbHmsssG s22g== X-Forwarded-Encrypted: i=1; AJvYcCVQMraCyomtERLAhTTjj4tTfBQvtJw2qs/Gq3LvnQUFCGNoOAcvFO3ozd1oSJOGjfrgAKTfmh38hmm/Aw34@postgresql.org X-Gm-Message-State: AOJu0Yx915pbWMYa2VA+/j4KsdJ95gOayAi5I222iERI6Z8EEd1t28wh qPIf4qRHTYSzQ57tm9A53Ltj6M2p7JUXQOr6A+3mIC/mPbiGprI85WuPIkvCbutqveRGbatkoIP cNpBQZWujSBagpAbHaiZPdjmTnzDl7B4= X-Gm-Gg: ASbGnctKFWaNC5m+zwvVVwg5Mwv2eyS0ogdoaYg18QRt+Vf/T46rpXuVDriYqAxNa47 6lVsBbxPPhLAb1JPivfPDJxRS7eWjfbGha9NcJbeC7unWVks2PJQxa76D/4WXobThnblDabV8RA /amTw7XyMPitYhHjcug/MpPdO9Gxzo1hisuKbbPVx4RP3klfqcC02Jb1MUcB3Ho4kfUVNllGj2X LGfi4vXNBlfjEZrRot5KmRDR9+f1go+Jk5/8mO9vdcE907YEOmzKG2uqe9KquCF X-Google-Smtp-Source: AGHT+IF2WaeBE1OHPvnnp7B52IClOTRnBcbyGiE2MHvjqZ7QcuipJ/h0t429pkNCYsJ/42yiI4n51YrF0r58np8xmGo= X-Received: by 2002:ac8:5d4d:0:b0:4d2:ba6f:28fa with SMTP id d75a77b69052e-4e6de8b5d39mr31930581cf.34.1759806753193; Mon, 06 Oct 2025 20:12:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Tue, 7 Oct 2025 14:12:06 +1100 X-Gm-Features: AS18NWAjz3Yn9GPKjc3CuuV79K9Q8kchPSilIi9ZF5hlsTT87IdFdlok2SZot38 Message-ID: Subject: Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE To: "Aya Iwata (Fujitsu)" Cc: Michael Paquier , "Hayato Kuroda (Fujitsu)" , 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, Here are some more minor review comments: ====== doc/src/sgml/bgworker.sgml 1. Typo? s/damon/daemon/ ====== src/backend/postmaster/bgworker.c 2. +void +CancelBackgroundWorkers(Oid databaseId, int cancel_flags) +{ + int slotno; + bool signal_postmaster = false; + + LWLockAcquire(BackgroundWorkerLock, LW_EXCLUSIVE); + + for (slotno = 0; slotno < BackgroundWorkerData->total_slots; ++slotno) + { + BackgroundWorkerSlot *slot = &BackgroundWorkerData->slot[slotno]; + + /* Check worker slot. */ + if (!slot->in_use) + continue; + + /* 1st, check cancel flags. */ + if ((slot->worker.bgw_flags & BGWORKER_EXIT_AT_DATABASE_DROP) & cancel_flags) + { + PGPROC *proc = BackendPidGetProc(slot->pid); + + if (!proc) + continue; + + /* 2nd, compare databaseId. */ + if (proc->databaseId == databaseId) + { + /* + * Set terminate flag in shared memory, unless slot has + * been reused. + */ + slot->terminate = true; + signal_postmaster = true; + } + } + } 2a. Declare slotno as a 'for' loop variable. ~ 2b. There seem to be excessive conditions in the code. Is it better to restructure with less, like: for (int slotno = 0; ...) { ... if (!slot->in_use) continue; if (slot flags are not set to drop) continue; proc = BackendPidGetProc(slot->pid); if (proc && proc->databaseId == databaseId) { slot->terminate = true; signal_postmaster = true; } } ====== Kind Regards, Peter Smith. Fujitsu Australia