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 1vcpgI-00BIid-0o for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jan 2026 18:51:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vcpgG-003law-37 for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jan 2026 18:51:53 +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 1vcpgG-003lai-1Y for pgsql-hackers@lists.postgresql.org; Mon, 05 Jan 2026 18:51:53 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vcpgF-004NIg-2g for pgsql-hackers@lists.postgresql.org; Mon, 05 Jan 2026 18:51:52 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-5957c929a5eso224206e87.1 for ; Mon, 05 Jan 2026 10:51:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767639109; x=1768243909; darn=lists.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=S4/CtFUhHdN0eXUJNOxXnFfNMe47+Kw2tvl13h51WxI=; b=XpazkHUI7DQPvCmjKFPz0vGDAP4F/rtx8d68EH6BLx5shdVdsHBvQipw3OrcG9BEtE 2Y9wmr7hSHBQftMhfY3qSHR55St6aep4qgANjAs1DwgSOmq/petuWQEzvsHh5TkA04jL KdgsAq+O6T53Z9DPK8gdiGdzW/KHez+XDuHaTMUwtCVctvR/+SAlSEM4GTFUkCKxr8Im U70ZWL/FXu8StnbLqkoIISvT+j5/Jkxp9j1U7vQAwXInRpfp3dQ88lMkUJDyL601PMb5 BhM9OhwZWM4i9q2ipDHASTiA7rBoUP7/sX8iuHR4G9Ke7S7JPHn4P0co6+TdTBiqR6U4 EsGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767639109; x=1768243909; h=content-transfer-encoding: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=S4/CtFUhHdN0eXUJNOxXnFfNMe47+Kw2tvl13h51WxI=; b=Nky+ewME2y4VT1MMoC4KfcCv0x9RYCBct3AxqQBFaOA71pskgf+gLSk0zibFblyZQb 6m2nBCCJ8bfa8fGW4nHUMxhQzqh0PsesJBJJnWwLQNZ0y57ordVmoovjsh44E1isJj75 BxbuFH0Honeb/acPBytqnBRPrKLAQaTSeb2utJP4M/CZmk1gNyEYMToIZGmotc9oXdX+ 9WKZ/nWvB9wE4hl8l5iERO3EfNXbkBsYF1T0NtkfLnesyJVYUTk0ciMmOkrDD3/U4jRk pZrTkF1muL6PlcLCEnLekFEkwdLv0i114mGEFiYSxHBld4e0NR++HcqbrIFZVEmZII/Z XueA== X-Forwarded-Encrypted: i=1; AJvYcCXe8w+dIGyJFd2XaeMjHG3VmEBrGGB0vuKEfiULfOcaSnKtORVKV6vKjNq520mwE0BUgpa9x7a/7YACra0K@lists.postgresql.org X-Gm-Message-State: AOJu0YyF8OOLh6oH8B6T+lqt4TKsgiDAKYjRsFsXdT8ugDh6f25T3CsT LPMInf2thnISY4piO3x3FMj2GEwEnXrB5v6C7CMIZfN/ohxAzSpTGbotDTFGjC8vZEylTxOsmyd wLXm8kHIeZn9rBpkMOXrfrRhP5KyAJ9hQkUjE X-Gm-Gg: AY/fxX7FCAst/0eXWRMCYKY9sCaJKwxih424RQEl4VDViQkRluvUL0YPC9+7/uCxezP k1Khjq9LbRpEZ3gHRxNJjnE1QpFEkVJrpE4b2kTg9Vh0EZeSwvH6ZrrFIaNQoaOmP3VswuV9rNg FpY2TcgAB4ZxFH6GckTNWO+mMHaVsfDb9M1+x0xBFxlsxfbz4/pqe99BMpbCtVqpp27ezbAbHDK l1JwvElX2i774JMxqscawyNx5hvsJy5w8kGw/YL9Xv1KC4TTC1OwbUiT97q6Y3MpvK5NCY2 X-Google-Smtp-Source: AGHT+IH1GLaiIBitnc4vPPWnlX/vDaSfwiuB1hCR5e5NKfrJSV2Z7tbAVDiMyzTuzOfFmRKaHHExUf447VkYUFd1cYo= X-Received: by 2002:a05:6512:ac6:b0:595:82d7:a275 with SMTP id 2adb3069b0e04-59b652bc698mr183128e87.37.1767639108303; Mon, 05 Jan 2026 10:51:48 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Mon, 5 Jan 2026 10:51:11 -0800 X-Gm-Features: AQt7F2okTJ2xsx0eUKspe6ID_zVB0mzBG_px6DKSO_houIOR8FczW2zjV154x78 Message-ID: Subject: Re: POC: Parallel processing of indexes in autovacuum To: Daniil Davydov <3danissimo@gmail.com> Cc: Sami Imseih , Alexander Korotkov , Matheus Alcantara , Maxim Orlov , Postgres 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 Sun, Nov 23, 2025 at 7:02=E2=80=AFAM Daniil Davydov <3danissimo@gmail.co= m> wrote: > > Hi, > > On Sun, Nov 23, 2025 at 5:51=E2=80=AFAM Sami Imseih = wrote: > > > > > > nworkers has a double meaning. The return value of > > > > AutoVacuumReserveParallelWorkers > > > > is nreserved. I think this should be > > > > > > > > ``` > > > > nreserved =3D AutoVacuumReserveParallelWorkers(nworkers); > > > > ``` > > > > > > > > and nreserved becomes the authoritative value for the number of par= allel > > > > workers after that point. > > > > I could not find this pattern being used in the code base. > > I think it will be better and more in-line without what we generally do > > and pass-by-reference and update the value inside > > AutoVacuumReserveParallelWorkers: > > > > ``` > > AutoVacuumReserveParallelWorkers(&nworkers). > > ``` > > Maybe I just don't like functions with side effects, but this function wi= ll > have ones anyway. I'll add logic with passing by reference as you > suggested. > > > > > >> --- > > >> { name =3D> 'autovacuum_max_parallel_workers', type =3D> 'int', cont= ext =3D> > > >> 'PGC_SIGHUP', group =3D> 'VACUUM_AUTOVACUUM', > > >> short_desc =3D> 'Maximum number of parallel autovacuum workers, th= at > > >> can be taken from bgworkers pool.', > > >> long_desc =3D> 'This parameter is capped by "max_worker_processes" > > >> (not by "autovacuum_max_workers"!).', > > >> variable =3D> 'autovacuum_max_parallel_workers', > > >> boot_val =3D> '0', > > >> min =3D> '0', > > >> max =3D> 'MAX_BACKENDS', > > >> }, > > >> > > >> Parallel vacuum in autovacuum can be used only when users set the > > >> autovacuum_parallel_workers storage parameter. How about using the > > >> default value 2 for autovacuum_max_parallel_workers GUC parameter? > > > > > Sounds reasonable, +1 for it. > > > > v15-0004 has an incorrect default value for `autovacuum_max_parallel_wo= rkers`. > > It should now be 2. > > > > + Sets the maximum number of parallel autovacuum workers that > > + can be used for parallel index vacuuming at one time. Is cap= ped by > > + . The default is= 0, > > + which means no parallel index vacuuming. > > Thanks for noticing it! Fixed. > > I am sending an updated set of patches. Thank you for updating the patch! I've reviewed the 0001 patch and here are some comments: --- + /* Remember how many workers we have reserved. */ + av_nworkers_reserved +=3D *nworkers; I think we can simply assign *nworkers to av_nworkers_reserved instead of incrementing it as we're sure that av_nworkers_reserved is 0 at the beginning of this function. --- +static void +AutoVacuumReleaseAllParallelWorkers(void) +{ + /* Only leader worker can call this function. */ + Assert(AmAutoVacuumWorkerProcess() && !IsParallelWorker()); + + if (av_nworkers_reserved > 0) + AutoVacuumReleaseParallelWorkers(av_nworkers_reserved); +} We can put an assertion at the end of the function to verify that this worker doesn't reserve any worker. --- +static void +autovacuum_worker_before_shmem_exit(int code, Datum arg) +{ + if (code !=3D 0) + AutoVacuumReleaseAllParallelWorkers(); +} I think it would be more future-proof if we call AutoVacuumReleaseAllParallelWorkers() regardless of the code if there is no strong reason why we check the code there. --- + before_shmem_exit(autovacuum_worker_before_shmem_exit, 0); /* * Create a per-backend PGPROC struct in shared memory. We must do th= is * before we can use LWLocks or access any shared memory. */ InitProcess(); I think it's better to register the autovacuum_worker_before_shmem_exit() after the process initialization. The function could use LWLocks to release the reserved workers. Given that AutoVacuumReleaseAllParallelWorkers() doesn't try to release the reserved worker when av_nworkers_reserved =3D=3D 0, but it would be more future-proof to do that after the basic process initialization processes. How about renaming autovacuum_worker_before_shmem_exit() to autovacuum_worker_onexit()? --- IIUC the patch needs to implement some logic to propagate the updates of vacuum delay parameters to parallel vacuum workers. Are you still working on it? Or shall I draft this part on top of the 0001 patch? Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com