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 1w2B5y-0003lA-37 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2026 16:47:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w2B5x-00BMvM-0B for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2026 16:47:09 +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.96) (envelope-from ) id 1w2B5w-00BMvE-2M for pgsql-hackers@lists.postgresql.org; Mon, 16 Mar 2026 16:47:09 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w2B5q-00000000SMd-2ys4 for pgsql-hackers@lists.postgresql.org; Mon, 16 Mar 2026 16:47:09 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5a12fbbd9d2so7463953e87.3 for ; Mon, 16 Mar 2026 09:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773679617; cv=none; d=google.com; s=arc-20240605; b=KutQD8tpKB/kKn8FnS5baJAwGRAGchHBIrTKMtuqua79epJOUNwjr97320jlFuRe7/ hGRjg3W4mo9XAwI9PwO8+YsrGtVnsjk8fQWntqLOZTHpm8y3dK073WKFPFm/Kxkz1fYw lSsK/ZWuX+flMbPWnD+A8FMhvURsRvIcri3F94g41OQuvLzRcyBz7WdvuK8WZmffgYdu zKffmCBc/JQPlBSdGpnr2gezkH32pCGKMlZOYZy+LFowLwdI5Sz7KIJfO0IpU9+seFBK p6bfPc00RLpH+KfwbK6Iyz6DCfZ6eHuNVVC4U9GYcmMIvBv/rZWnn78KUVOVcwXjPmFG 2wCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=VUVNO9vo8vZMcJOSAxx0DttIT0DnoKJXIRIPyuHGACQ=; fh=r2OOvLvnrDYUIpmUJyKxng4erscx7HAy0LMmSbJdZqw=; b=gJ6CiG5U5MUK5QYIwovf1fgLpDiiF4ScbQirdZkNOKLjd/nDohjHGbedbG7+CA8XsM d4ilxR9Xi7wf2LoU4AhIixuJzEEXUmPrg/InFI5OwIqPwNWJXA6hPhX/M6ff8Qivrbkb raBq0SnCNOYU7w1Q79E/9Dt+zotdWDxJ7qBHn8GrR9eT3/C/PAhXACCCkL5qEi9Tw3K8 s4mTps4RWshvVAs0bXj/qFwoS5P5hak1qS1lje9BXNH1NY7TGU8txq7fuHTutWrKZTB7 SbVXbiMOcpLvuwZTEE9ZmAcyD7sUI+IZxhJEsjBwE09/vhgWltMThnJfhXDYYusALO9s jfjQ==; 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=1773679617; x=1774284417; 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=VUVNO9vo8vZMcJOSAxx0DttIT0DnoKJXIRIPyuHGACQ=; b=PcbmfkYXgIIVr6LUdxIGuGUPCYV8P8bDeDcdmPqMfBO0yuO/wFYzOAARUvwY41zPuP mGGwHrbdQZXWhQt+t7Bl3tinenFreiPaZMIZQjTfg416x1x8IYKP8W0yLKsOOtQfzvBG rj7UIOAnnZSL0eZWpQx9KCLAFQHpkKKBdUigUrGEQonSHxxx+9QOioiAKB5IpJuOIv1F HSQV10nC1OZ+c4TsFazpf5SuCXirt6byw+nqSmG5qg3ENnMzeXvSQjOCt2OeU+KeGUnN 15jHgji21Jl9YOAPkm51fdBG20uLNsBDBkmsD8R4evBLYXZQ8J3fSQB6B02YVK5vdKeS 3ivg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773679617; x=1774284417; 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=VUVNO9vo8vZMcJOSAxx0DttIT0DnoKJXIRIPyuHGACQ=; b=m2PKV6KBoaVn09DvVHbTaqKT+7xVm865EoYfzcCwBeHBEVxLCnc027RRZV8l5wdDlm 6tpuPo1BunVlLioyIrG2UCX/FhaCgQZuRZ5jjT9dezgQvTqKCLazVt24R60WseW8tUGE EvCs9nPNl4vWeNNLmUg7F6loOR38goYwHVTkJ6JbSMdrcMaQGYX4V2liv5HepnC9P6LQ K9l1mW4C9UCpQcxi6T0o1TpkvHryIWZrHLowUnLresljHc4h0Z9DoQQAQ5zt3Can+8oN uoqLAOjPtRv8cn3aI40khX3kwFQfEzyW81Ly6pLO2IUJroeWwtZ+bK4Q5+pCSr763VpT wZ5Q== X-Forwarded-Encrypted: i=1; AJvYcCV63HjLaHyrDxdTXQYDn69nw+l1yGaQfVnE4ZDZ+ZafSR1Uao1H6o3fljko6InR/zrWK6iuaf7TxDoJoOp8@lists.postgresql.org X-Gm-Message-State: AOJu0YyVDU+sbcwTDjTJ4FRgG0tclJpvKlQ+gMnQPQR/WrhpoeZgLiGo W8wBBjlCEhtZfIOnE8WpyV4eyAmC0kw8GedFxJpgenIZ5TTX+CB7mtJsXmAQZSzX5rZcSQQzEbb pB6MMxG7RO7IP9OLD8N8530hjuoz3Ncg= X-Gm-Gg: ATEYQzxzD+jssk9XsbrFw+9scHlVSwcn4sq1XI06aOPdT8qcLKMc6eSa+q5CfroFOoP SgP84ZcJ6dGZrVIeJGgzCP6tkalzHC77grvIjcYrn4pM7Y0gt9kzGepm7hahiYxvxHd9pmKIzVQ 4um1lVDZxg2zawH3oX5xe1Ag4flRh/0iYJVRLG6+sTyaO9OpHmMUbGyserrTRDUZB+3eawlcqAR XG6jWUV5dJJ5cJgh1Sn83H2Eoy3X277QHfWtwqEJHdVnebdRIqMcveXgSyDcSElaBVLZfdt/G9t efP2wogj X-Received: by 2002:ac2:4885:0:b0:5a1:53a5:b096 with SMTP id 2adb3069b0e04-5a16270ee05mr3484053e87.19.1773679616581; Mon, 16 Mar 2026 09:46:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Mon, 16 Mar 2026 09:46:19 -0700 X-Gm-Features: AaiRm51mqHwVm1_Jj_Assro-j-sTzBjpqIHDIWYSLkw2ECPdb3i9Mqx-aZHJct8 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 Mon, Mar 16, 2026 at 5:34=E2=80=AFAM Daniil Davydov <3danissimo@gmail.co= m> wrote: > > Hi, > > On Thu, Mar 12, 2026 at 2:05=E2=80=AFAM Masahiko Sawada wrote: > > > > BTW thes discussion made me think to change av_max_parallel_workers to > > control the number of workers per-autovacuum worker instead (with > > renaming it to say max_parallel_workers_per_autovacuum_worker). Users > > can compute the maximum number of parallel workers the system requires > > by (autovacuum_worker_slots * > > max_parallel_workers_per_autovacuum_worker). We would no longer need > > the reservation and release logic. I'd like to hear your opinion. > > > > IIUC, one of the main autovacuum's goals is to be "inconspicuous" for the > rest of the system. I mean that it should not try to vacuum all the table= s > as fast as possible. Instead it should try to interfere with other backen= ds > as little as possible and try to avoid high resource consumption (assumin= g > there is no hazard of wraparound). > > I propose to reason based on the case for which the parallel a/v will > actually be used : > We have a 3 tables which has 80+ indexes each and require a > parallel a/v. Ideally, each of these tables should be processed with 20 > parallel workers. This is a real example which can be encountered in > different productions, where such tables take up about half of all the da= ta > in the database. > > How parallel a/v will handle such a situation? > 1. Our current implementation > We can set av_max_parallel_workers to 60 and autovacuum_parallel_workers > reloption to 20 for each table. > 2. Proposed idea > We can set max_parallel_workers_per_av_worker to 20 and > autovacuum_parallel_workers reloption to 20 for each table. > > In both cases we have guarantee that all tables will be processed with th= e > desired number of parallel workers. And both cases allows us to limit the > CPU consumption via reducing the "av_max_parallel_workers" parameter (for > current implementation) or via reducing the "autovacuum_parallel_workers" > reloption for each table (for proposed idea). So basically I don't see wh= ether > current approach has a big advantages over the idea you proposed. > > I also asked my friend, who is many years working with the clients with b= ig > productions. He said that this is super important to process such huge ta= bles > with maximum "intensity". I.e. each a/v worker should have ability to lau= nch > as many parallel workers as required. I guess that this is an argument in > favor of your idea. > > The only argument against this idea that I could come up with is that som= e > users may abuse our parallel a/v feature. For instance, the user can set > "autovacuum_parallel_workers" reloption not only for large tables, but al= so > for many smaller ones. In this case the max_parallel_workers_per_av_worke= r > must be pretty large (in order to process the huge table). Thus, the user > can face a situation when all a/v workers are launching additional parall= el > workers =3D> there is high CPU consumption and possibly max_parallel_work= ers > shortage. The only way to deal with it is to go through a large amount of > smaller tables and reduce "autovacuum_parallel_workers" reloption for eac= h > of them. IMHO, this is a pretty unpleasant experience for the user. On th= e > other hand, the user himself is to blame for the occurrence of such a > situation. > > Let's summarize. > Proposed idea has several strong advantages over current implementation. > The only disadvantage I came up with can be avoided by writing recommenda= tions > on how to use this feature in the documentation. So, if I didn't messed u= p > anything and you don't have any doubts, I would rather implement the > proposed idea. Thank you for the analysis on the new idea. While both ideas can achieve our goal of this feature in general, the new idea doesn't require an additional layer of reserve/release logic on top of the existing bgworker pool, which is good. I've not tried coding this idea but I believe the patch can be simplified very much. So I agree to move to this idea. > > > > 2) > > > I suggest adding a separate log that will be emitted every time we ar= e > > > unable to start workers due to a shortage of av_max_parallel_workers. > > > > For (2), do you mean that the worker writes these logs regardless of > > log_autovacuum_min_duration setting? I'm concerned that the server > > logs would be flooded with these logs especially when multiple > > autovacuum workers are working very actively and the system is facing > > a shortage of av_max_parallel_workers. > > Oh, I didn't take that into account. But this is not a problem - we can > accumulate such statistics just as we do now for the "nreserved" ones. An= d > then we will log this value with all other stats. > > > > Possibly we can introduce a new injection point, or a new log for it. > > > But I assume that the subject of discussion in patch 0002 is the > > > "nreserved" logic, and "nlaunched/nplanned" logic does not raise any > > > questions. > > > > > > I suggest splitting the 0002 patch into two parts : 1) basic logic an= d > > > 2) additional logic with nreserved or something else. The second part= can be > > > discussed in isolation from the patch set. If we do this, we may not = have to > > > change the tests. What do you think? > > > > Assuming the basic logic means nlaunched/nplanned logic, yes, it would > > be a nice idea. I think user-facing logging stuff can be developed as > > an improvement independent from the main parallel autovacuum patch. > > It's ideal if we can implement the main patch (with tests) without > > relying on the user-facing logging. > > OK, actually we can do it. > > > > Thank you very much for the review! > Please, see attached patches. The changes are : > 1) Fixed segfault with accessing outdated pv_shared_cost_params pointer. > 2) "Logging for autovacuum" is divided into two patches - basic logging > (nplanned/nlaunched) and advanced logging (nreserved). > 3) Tests are now independent of logging. Thank you for updating the patches. I'll wait for the new implementation and will review the patches as soon as the patches are updated. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com