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 1v6cVR-007P4v-T0 for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Oct 2025 22:19:33 +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 1v6cUR-00DUrX-9X for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Oct 2025 22:18:32 +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 1v6cUQ-00DUrI-Vk for pgsql-hackers@lists.postgresql.org; Wed, 08 Oct 2025 22:18:31 +0000 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v6cUP-0017Aw-1N for pgsql-hackers@postgresql.org; Wed, 08 Oct 2025 22:18:31 +0000 Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-4de1b5a6b7fso2535301cf.2 for ; Wed, 08 Oct 2025 15:18:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759961907; x=1760566707; 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=qo2DkLdRUlDmlYYIkKG0Sdyk0M4JvrOtcOvLO1qCB1U=; b=AclB4sBOwx5VdnS8flaPbQqHG8497l4sTVRDIW4RDshekK87OPrBeNNrdktqtGI5Wl uFM1DQoDlasLqJ927Xm9dbKg1DXEPspHb2OzBmFn376zhMMdwaTNt7sZcis7ESjHpQ9w /P+KiFSZeHGcao0eUCiJq43akzDW3SwDKxRARstHobrmbSC44WSv7zFY6maFR3YGPXlx kUeMw8L3hyYCmf5pFJ3es9157TlUeAyz8a1fQO+ipdgs6H5+yKpqxnTUytSgBZ2PIxA4 cnV+CdTltTfE3VwTizeG3AMPXVy6lvzsvJ3wp5fCtZm3jL5WXns/RQEiHINCc1cMIVQd +NDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759961907; x=1760566707; 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=qo2DkLdRUlDmlYYIkKG0Sdyk0M4JvrOtcOvLO1qCB1U=; b=HeHhEhuJyC7DMVRb/fjaRxoLXcAmoKDEtpI2MmG2p+0JdyTG0A/0nsBOgBUFkSGgbJ HSsUxleJ4ZETt1YNxlhkUBipIf8GAnuACQjqI8Du3yk9NKCsKjsIKvj+aW6qOBDdSfcw r4aCyyjpiNUQ6ya2hxC90E0XcUuoYM92Eld6Z3RUsmEB9gZM0y6/kUD/B0xDYFiZ2Eg2 CDxnospcEMpahYw6ni1ZrXisMTcJGUsluUV9am1qASVDHfzibhO66Bt7QCCzOCgu7k8O tNGCJknQHNrn4Gb9QdcJPneCtmpx7wq4smXPNg+6DCX9KVgX8nlIvZ0VzN7ii+3Ax7Ow uAyg== X-Forwarded-Encrypted: i=1; AJvYcCVstffzy9yaudeqBfh7me9yaLrHmpIhoLkwXDrk0zrR5egb7rUMsXi2Z79MdQZjDnv15/SCPvPsYPfobda1@postgresql.org X-Gm-Message-State: AOJu0YwQ5jOEE7xGthlELTcgMwHLu6E0nLsOJGdoR9bNIf0sAA2sQlCF 1jJdLZCsVUP7TTNa1RkL9ViqkQ06PVyPHW6uzj++KN2gOk7OtgAvDU+yBlfMD2bT/al4klGM4Dh BUYwJPMJy10+Gba8jJ9oGgJ+IpcgbrFk= X-Gm-Gg: ASbGncvfgHLwpiw6rsu0xZRa6lXyzP2KdaPv9ASL4gdM151b4x45222sT9H5n/rleUI 2BrWXHGQsT98xa9RH+9Vv4QBSYVF4v5mh+HeDwUxToj0A2lfgF4Kuki7/twwDVDcNjbqwK7t294 Dy12oiQjy11S6O5ClPG6vyPWnEnO0Atg9Lwdu995TBJqVYv2+QWVlffzUeBQ09nYgiIHj+Kf5is 9i3DVKQYgTmKo68oyTEpovZbvw2bRVHr/O3Yc1EP0L/R0qn96GwShN7pBYTCyWB X-Google-Smtp-Source: AGHT+IEYH6QdaQVG7PQDQSS8r/OU6+y4Mg4E1o8iK5utx70t+HhyxDt8q/gDKVsZvhI/Q3qDPalU0RgXF2yH1zaZzyQ= X-Received: by 2002:a05:622a:343:b0:4ce:6ded:dba4 with SMTP id d75a77b69052e-4e6eacf6addmr79069781cf.19.1759961906737; Wed, 08 Oct 2025 15:18:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Thu, 9 Oct 2025 09:18:00 +1100 X-Gm-Features: AS18NWB5uhGbirqaFKwCoNwAT7rZdoQK8wzmK759SROmSGBn4M98tB6xX4w3n8A Message-ID: Subject: Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE To: "Aya Iwata (Fujitsu)" Cc: "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 v4 comments. ====== src/backend/postmaster/bgworker.c 1. + /* + * Set terminate flag in shared memory, unless slot has + * been used. + */ + for (int slotno = 0; slotno < BackgroundWorkerData->total_slots; ++slotno) + { + PGPROC *proc; + BackgroundWorkerSlot *slot = &BackgroundWorkerData->slot[slotno]; + + if (!slot->in_use) + continue; + + if (!(slot->worker.bgw_flags & BGWORKER_EXIT_AT_DATABASE_DROP)) + continue; + + proc = BackendPidGetProc(slot->pid); + + if (proc && proc->databaseId == databaseId) + { + slot->terminate = true; + signal_postmaster = true; + } + } 1a. It's not clear to me what you were trying to convey by saying "unless slot has been used" in the comment. Maybe you meant "unless slot is not in use", but is that useful even to say? Anyway, the comment as-is seems incorrect. ~ 1b. Sorry for wavering on this, but now that I see the resulting v4 code, I feel we don't really need any of those 'continues', and more if conditions can be combined. It becomes simpler. See if you agree. SUGGESTION: for (int slotno ...) { if (slot->in_use && (slot->worker.bgw_flags & BGWORKER_EXIT_AT_DATABASE_DROP)) { PGPROC *proc = BackendPidGetProc(slot->pid); if (proc && proc->databaseId == databaseId) { slot->terminate = true; signal_postmaster = true; } } } ====== src/backend/storage/ipc/procarray.c 2. + /* + * if set the bgw_flags, cancel background workers. + */ + CancelBackgroundWorkers(databaseId); + I was wondering about this function name "CancelXXX" -- do you "cancel" a worker, or do you "terminate" it? Isn't it better to name this new function more like the existing/similar TerminateBackgroundWorker() function? E.g. consider the following: /* * Terminate all background workers for this database, if * they had requested it (BGWORKER_EXIT_AT_DATABASE_DROP). */ TerminateBackgroundWorkersForDB(databaseId); ====== Kind Regards, Peter Smith. Fujitsu Australia