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.96) (envelope-from ) id 1vigau-00D73E-0r for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Jan 2026 22:22:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vigaq-009jIi-2g for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Jan 2026 22:22:29 +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.96) (envelope-from ) id 1vigap-009jIZ-37 for pgsql-hackers@lists.postgresql.org; Wed, 21 Jan 2026 22:22:28 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vigal-001fF2-28 for pgsql-hackers@lists.postgresql.org; Wed, 21 Jan 2026 22:22:25 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-b87693c981fso44975266b.1 for ; Wed, 21 Jan 2026 14:22:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769034143; cv=none; d=google.com; s=arc-20240605; b=E2pSojdda9eV/8Ti5GdJR9q+OW+Ef9aRmQ7+uS1OX7/fmpsVxRrlQeMLHYSC6EIyMe Xz3HghEwTb+sIoRE2Rc9Kdhg8mr27IWOodnaJPedFxMJP9fRG3j5WpR/k9gqdwKVolOM hJCgxg1g8SO7u4WgeLpwrNaDZ8pd/SjwJqKeOEbfsqXFwdVEeCc8dkeJs1bYKF++2TUL OfqdNOqGm4+f6gw/2pfJEJZvxyQN1HgIxYoUqibnccAFXb1ssuki9X57FnNVr6PAUcn9 GUFRqocZy5MrtJb/ZO3ZB/v9X9ZWpyNNBXt8GYoVZAswSU9x+pAbs99mIaTv2tNms4n/ PrBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=3VrSP4fmO/qR+kfoWL2B1/6dVhJO37tfLXIoZovSlg8=; fh=h5tK7zsn6UKoNp/tk7da61ty2Mtxs2ICYoyGFrXU4Yo=; b=Tq/PnPjIJ655sgyILMrQk4gtTudhN7hBnJs4iB+G8aUOdN4dsr0rZtClX1G5vt4i/S 9dFcraK2XkzfGpfoPSB+N/Fg2r9Xuvo8Wg0/07eNBL0jOZ2lnYzu5D+iGiL3kZPqXnsX u5RGXO4TkedK7SPG2Mhifd9GBecbeyC3JUu/w5N6NXwSRT/fIdUvIt2q9YESJiuFcJ9U g6GyI9trEIhcuJOc1SWBf4w2RCnMZKidAN+wIfwGCEeTQD3aNFZ9OfLvIGRSo7qKeF5Q 5iQ0mfarxRRl0aLO7gtOxbT78JYbXvWm5ccZlrZFDnQAmJgTbC20J/37z9XeKz7gjst2 CuKw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769034143; x=1769638943; darn=lists.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=3VrSP4fmO/qR+kfoWL2B1/6dVhJO37tfLXIoZovSlg8=; b=JizgAZogsIKIVecgCBRgd3xxF8HRogs6BarLANcgYt24CZr3r4hzFlVD80zx+LUUSj 7r59ZQ3BX9bw6HDhs98FB0Xemw8uHo8dnc+Q3lbyxg2po4Rt9gxGfDZ+NS+A2+TLfd2+ akjtutMYjkQwQdQeMinrV8XjldgCPN7A0GW0nFwCWkad8bpjErx7br/IuGHFjHz0kZvd snJYvXeU0GMX8Hl1hRc2XP40/UFmiqvRo8C9F77wFjBSzrT8U7po/GH1PHmjPcojH3b/ U7oIlME/3reJF1oCGRs6EjjsecJwIbTWjkXDagPw6bRiip3LcDJwM6bWjSau+fb8WIeB WTlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769034143; x=1769638943; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3VrSP4fmO/qR+kfoWL2B1/6dVhJO37tfLXIoZovSlg8=; b=arpB9nSPRtyj8upYqDw5rfDkqsMPgFJikeh9Lawmm0Fc0RywCPR0stFkloAMRHcfW9 UY1/TcAktR5rZtehxlJfcidd0ry579McJybKN12/kGPReD2BkSUbi4vDVurT/eO9W+xp ZGSkG3Mx97LasphjHMtE0tK+J8ngX5Sv90do9Fp75m9XJN3S3kRtgLEg56Lt2Ow2i8H4 e027K+f2RWE/t3kvkvfm8+Zbfzm42G1pDJvhfby+BiiYcSbix9iPdA6XCTmsvhRC1BC1 wcNf5tI6Q8B5Lg2kFJmaXLqZH2X7dzcBCzqZDt14d6cvuF3kwmtuqCC6XZYm9gDEGyfc X0nA== X-Forwarded-Encrypted: i=1; AJvYcCX7OiF+pJi094O/LI2aj2ItD1BLWrOmF2qQBjWYOEaD8zmmzv0f3lHTJZGaHAI6fbVfNmxpHiyR8Jwrh8JW@lists.postgresql.org X-Gm-Message-State: AOJu0YwovB0WUKUCfLtwvlshhO8Z/lHAHGVpCGgVjG14VHm4mtRrycKu b5MJSP8AsfLI28bASILc2BFNYYaV3qRdVbMCYQ8d1U7YOQc23Kto3LzxnCz8rk27fueodYmRy4m 9YNbnAiqvG/37zLdZqDmQWhMfbZovQc8= X-Gm-Gg: AZuq6aJuRh3GA4qOsf+UZHfVzfDQokmYDZxLiMiYmvk2HWk0r0607TuvmTJ4XkJippC 0kld+5J93sSD54D76HTUXVzg+tkRR2YXGNbX7MSxoaYLQjlh50J9fyWVdtISk6nOiEjKeKxYouU xROYTyFRAPIHGQmXYcSK79xtpv/n7xbmg6VcRIfSuz03VRUuEexHs8hYq76XqXvXAY40nFzHv/d EN7OJMciKsueuZlPzw0IKC6ClAkZz0zT9PbUW3yhBg5XdEesU9wc4xg+Bnw0a36neeNrg== X-Received: by 2002:a17:907:3e04:b0:b79:d24b:474d with SMTP id a640c23a62f3a-b8792d590e0mr1529900266b.16.1769034142624; Wed, 21 Jan 2026 14:22:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Wed, 21 Jan 2026 16:22:11 -0600 X-Gm-Features: AZwV_Qgaf1w7sfj7buI6yFhMbrwpE1pMtGm0mf-xge_lcqciLNQQSx-zIAdfb7Q Message-ID: Subject: Re: POC: Parallel processing of indexes in autovacuum To: Daniil Davydov <3danissimo@gmail.com> Cc: Masahiko Sawada , Alexander Korotkov , Matheus Alcantara , Maxim Orlov , Postgres 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, I took a look at v20-0001,0002 and 0003 and have some comments. v20-0001: 1/ ``` + + /* + * Cap or increase number of free parallel workers according to the + * parameter change. + */ + AutoVacuumShmem->av_freeParallelWorkers = Max(nfree_workers, 0); + + /* + * Don't allow number of free workers to become less than zero if the + * patameter was decreased. + */ + AutoVacuumShmem->av_freeParallelWorkers = + Max(AutoVacuumShmem->av_freeParallelWorkers, 0); ``` This can probably be simplified to: ``` AutoVacuumShmem->av_freeParallelWorkers = Max(nfree_workers, 0); ``` v20-0002: 1/ I don't think showing "reserved" in the logging is needed and could be confusing. ``` parallel index vacuum/cleanup: 3 workers were planned, 3 workers were reserved and 3 workers were launched in total ``` Also, even though the table has `autovacuum_parallel_workers = 2`, I see 3 workers. This is because one worker was for cleanup due to a gin index on the table. I think it's better to show separate lines for index vacuuming and index cleanup, just like VACUUM VERBOSE. ``` INFO: launched 2 parallel vacuum workers for index vacuuming (planned: 2) INFO: launched 1 parallel vacuum worker for index cleanup (planned: 1) ``` otherwise it will lead the user to think 3 workers were allocated for either vacuuming or cleanup. v20-0003: 1/ inside vacuum_delay_point, I would re-organize the checks to first run the code block for the a/v worker: ``` if (ConfigReloadPending && AmAutoVacuumWorkerProcess()) ``` then the a/v/ parallel worker: ``` if (!AmAutoVacuumWorkerProcess() && IsParallelWorker()) ``` But I am also wondering if we should have a specific backend_type for "autovacuum parallel worker" to differentiate that from the existing "autovacuum worker". and also we can have a helper macro like: ``` #define AmAutoVacuumParallelWorkerProcess() (MyBackendType == B_AUTOVAC_PARALLEL_WORKER) ``` What do you think? 2/ Add ``` +typedef struct PVSharedCostParams ```` to src/tools/pgindent/typedefs.list 3/ + pg_atomic_init_u32(&shared->cost_params.generation, 0); + SpinLockInit(&shared->cost_params.spinlock); + pv_shared_cost_params = &(shared->cost_params); NIT: move SpinLockInit last 4/ Instead of: ``` + params_generation = pg_atomic_read_u32(&pv_shared_cost_params->generation); + ``` and then later on: ```` + /* + * Increase generation of the parameters, i.e. let parallel workers know + * that they should re-read shared cost params. + */ + pg_atomic_write_u32(&pv_shared_cost_params->generation, + params_generation + 1); + + SpinLockRelease(&pv_shared_cost_params->spinlock); ``` why can't we just do: pg_atomic_fetch_add_u32(&pv_shared_cost_params->generation, 1); Also, do the pg_atomic_fetch_add_u32 outside of the spinlock. right? -- Sami Imseih Amazon Web Services (AWS)