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 1v6FPr-001b5F-24 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Oct 2025 21:40:15 +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 1v6FPo-0048mw-Nt for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Oct 2025 21:40:13 +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 1v6FPo-0048mo-DA for pgsql-hackers@lists.postgresql.org; Tue, 07 Oct 2025 21:40:13 +0000 Received: from mail-qk1-x730.google.com ([2607:f8b0:4864:20::730]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v6FPm-000YmT-05 for pgsql-hackers@postgresql.org; Tue, 07 Oct 2025 21:40:12 +0000 Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-856701dc22aso690549785a.3 for ; Tue, 07 Oct 2025 14:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759873210; x=1760478010; 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=WDDSMERK9Afgt5XzTpZElBsrZsygswBTnqdnTENTTs0=; b=hOeL7NhiymY2L5XmNx7NLq2tSIxW7IDF7zRhwPQktDHl4DVOOJC8a9Kmk/ufX79MER CKk1D9WJ66nRVbs6gjIGBEK2N8GhY1/4fR42A4TIqgo5zIEtVSfz/agS0ohnGFUzALxC jRAJk+jbkCZwN1E0pDMjxAxA/pdkQw7bZAsLYjES9Wc8lbK25eNLVZgBIL+J2D+HL446 ClhqnkVIpgjg21kU4335FurUnoKnk7ll0qXCxoZslMXMZNvoy2Yu0IFgegUW21vBWtE+ XFtzR7wGrqspUEIJMOxHYzJB3QdOMEFTqprfuUZO4p8v0irJdoFng/PK9GaZ2U7FBOMZ 2tuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759873210; x=1760478010; 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=WDDSMERK9Afgt5XzTpZElBsrZsygswBTnqdnTENTTs0=; b=uAtzpNEHoEi/WfBJpwYyVPBuNIcEnzU8zd9SYrI53d2f/157dEtM4O8tjCNFyb6eET ZYwrIMF2N5BUgMwTJrrViyaOGh/Zw/z2mKFkQwzXGY57z0IlGwOYTGp4LKcAgjHNQubD kMEfsYVgcpwcmuE3ioWy0RtSH4BFOO5j4oZ/qphPXgPJHm5lg8Nu1CqZ6wbMG2mOaH72 8FKQcMxrhRqAICQ34s6UFmh+/pMFFOPKw9RAHfCBewGhtfoE5GvvPSpklYxSGC14Mc1Z ldF32ye2qD8ju2Bh3wIbi7y9IRUMtpPiw6g76qxhTR21CbU7axnIncMDDvC3UVZLFlzU LW0Q== X-Forwarded-Encrypted: i=1; AJvYcCUKhgp4jzjCWg/haO52TIoDiTg74dNXffCm5Kf/tUTe72EVvJi8fgbok1iF53E1sJTqzlApOiUy3jCkZfPU@postgresql.org X-Gm-Message-State: AOJu0YwYB74AO1jPc0QxcY1Md35zaX7GcxKP+W0oqrHoI0VCVtA+wDQT A1LgIROtQSRUUk3unfpa5lJDkMyR0EJzXB+zqHTxRVIqPzmOLlT1jIkZ/+NuPuQv81HMBFGk0BO TFeWaYC8XJ+PRy9kfppjOBE+qN7xeCt0= X-Gm-Gg: ASbGncvvqK9/GUkhaipcKyXNNe6HR0qD83HNW8LCf0stc0LtgrTSffbF58JQ2bwBBxN Lk9cNGmFL23d+PxzVD1qGh5HIa9/XfmypntMiSLcWxcLpsC1etNx+HaGfhDN/TiOgIOHBKYb5Gp XYVCqoJ5C1byS3BjXJKxz/b/H71U9QbkoRr/dWjMtv/2LzIh3hS69Zh9NAswBD+aKWE7XCLmkVg sdyJYBOWrdGdUlBl0d5BdUx77txYJOJuQ0wiba8Ko8zyh1fcCYpT+XHIJJPpwcNvA== X-Google-Smtp-Source: AGHT+IFEsrTUJWkJGHYxegewFB2L3BBWy6X6s5KUpLKlwpJmvVNvvLw6G+A4/r6+aysRO3Z3eY0YiLzMFIivL6XbOzo= X-Received: by 2002:a05:620a:708d:b0:862:dc6c:e7ec with SMTP id af79cd13be357-8834fe99853mr172324185a.5.1759873210009; Tue, 07 Oct 2025 14:40:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Wed, 8 Oct 2025 08:39:43 +1100 X-Gm-Features: AS18NWCI2IAuab7SeQPpGAXYtB9PvR843xwjbKpTljjsQtm5b2JRfQuV5vo1jyY 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, Here are some more review comments for v3. ====== doc/src/sgml/bgworker.sgml 1. + + BGWORKER_EXIT_AT_DATABASE_DROP + Requests to terminate background worker when the database connected by + the background worker is changed. DBMS daemon can issue a termination + signal to the background worker. + This occurs only when significant changes affecting the entire database + take place. + Specifically, major changes include when the DROP DATABASE, + ALTER DATABASE RENAME TO, and + ALTER DATABASE SET TABLESPACE commands are executed. + Here is a reworded version of that for your consideration (AI-generated -- pls verify for correctness!): BGWORKER_EXIT_AT_DATABASE_DROP Requests termination of the background worker when the database it is connected to undergoes significant changes. 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, or ALTER DATABASE SET TABLESPACE. ====== 2. + for (int 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) + { + PGPROC *proc = BackendPidGetProc(slot->pid); + + /* 2nd, compare databaseId. */ + if (proc && proc->databaseId == databaseId) + { + /* + * Set terminate flag in shared memory, unless slot has + * been reused. + */ + slot->terminate = true; + signal_postmaster = true; + } + } + } IMO, most of those comments do not have any benefit because they only repeat what is already obvious from the code. 2a. + /* Check worker slot. */ + if (!slot->in_use) Remove that one. It is the same as the code. ~ 2b. + /* 1st, check cancel flags. */ + if (slot->worker.bgw_flags & BGWORKER_EXIT_AT_DATABASE_DROP) Remove that one. It is the same as the code ~ 2c. + /* 2nd, compare databaseId. */ + if (proc && proc->databaseId == databaseId) Remove that one. It is the same as the code. ~ 2d. + /* + * Set terminate flag in shared memory, unless slot has + * been reused. + */ This comment is a bit strange -- It seems slightly misplaced. IIUC, the "unless slot has been reused" really is referring to the earlier "slot->in_use". This whole comment may be better put immediately above the 'for' loop as a short summary of the whole logic. ====== src/include/postmaster/bgworker.h 3. +/* + * This flag means the bgworker must be exit when the connecting database is + * being dropped or moved. + * It requires both BGWORKER_SHMEM_ACCESS and + * BGWORKER_BACKEND_DATABASE_CONNECTION were passed too. + */ Not English. Needs rewording. Consider something like this: /* * Exit the bgworker when its database is dropped, renamed, or moved. * Requires BGWORKER_SHMEM_ACCESS and BGWORKER_BACKEND_DATABASE_CONNECTION. */ ====== Kind Regards, Peter Smith. Fujitsu Australia