Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pm1gU-0002oa-2d for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Apr 2023 00:16:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pm1gS-0001jH-6O for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Apr 2023 00:16:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pm1gR-0001j6-NM for pgsql-hackers@lists.postgresql.org; Tue, 11 Apr 2023 00:16:27 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pm1gP-0005RJ-1J for pgsql-hackers@postgresql.org; Tue, 11 Apr 2023 00:16:26 +0000 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-517bd9b1589so465145a12.1 for ; Mon, 10 Apr 2023 17:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681172184; x=1683764184; 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=1YJGxH7kr0110xMd9lrh910KDJhBnhMSK7YrU7hUqw8=; b=StJccHfc7pFD6IKlnW0LTMl5SWXO9C8JsxKYjVd+Ek0UmPu8WsF87D3Bv0URbZAB+U JDmQfzA0WawVAa1BskSM7TtLUURUuapJV6MyVycas7CwZcOCs73WEsimmj7W4I98VBAG nGg/UgtT0GTRTTGGWzl2ZS1OMkidunCvWlp8jllM4isClc5OgUBzJxwiOunGQ6wOslzH AJ4HJVPi3rHb8Y9PUsyhF8qFguFSq/Y7ws+2ejvSfkVgOf98BGY2zl/XkMEn9jfkd+1f 0imq4FEr+SkO4/UH46ZUXa9pQDB2yKnT+/dTzre2qwf4msYY1V4TL8FfEoq8mlvwyOJB HEUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681172184; x=1683764184; h=content-transfer-encoding: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=1YJGxH7kr0110xMd9lrh910KDJhBnhMSK7YrU7hUqw8=; b=mGpIYlRYD863uRsP8JkpdSoOAWJZ08Kx1Cm+fvyy5Ux+8ccbTaOTEz9xZ1UKwFluxI fu2X+clWddI54KNxhS61zoALiMeXvKzaG0kEGS6aHACJS/vZ+UzZdNLiiYuDbWXGS/pO Yw9tdiFUgiM+XDK7/bt918x7AHpWeX9YdWwJX/tu855pfh4CH2O1O82iDf8RgWQAAx7z ffvl5tmKJD8Jdz5jYZoLLeFk8zYrHSLszHRJKkUTOmTpthxNueZBG+FWFyEFC75EnQ46 fJK7TvjrcrtqPzc/F49B3uV/laFlo+ajS0HeW/GjTheC1ZStLycVu7TGzVG4XL+RSzJb 0oxg== X-Gm-Message-State: AAQBX9dfdWT1pQQy39zNtkUF2AGE3Vp9lF2Z/29wCI/6wY5l88cASc5x tD1NnOrkDkOHbOckO2kuZT7iaGVkAkpW76vQufb0sT77 X-Google-Smtp-Source: AKy350ZQlJwGJMibc0t1ZndfV3tOLIZ28/BlU2a/DhywPV5c4F5RwwdBCZ+cpTPIuJwleVZdT38ZjU6XpzVnrhe6aBs= X-Received: by 2002:a05:6a00:2182:b0:628:123c:99be with SMTP id h2-20020a056a00218200b00628123c99bemr5672346pfi.2.1681172183750; Mon, 10 Apr 2023 17:16:23 -0700 (PDT) MIME-Version: 1.0 References: <20230329.132155.629765142788133576.horikyota.ntt@gmail.com> <20230329.173456.1185961934810139447.horikyota.ntt@gmail.com> <935191FB-083B-4060-89FC-466F61FAA391@yesql.se> <1252075.1680547394@sss.pgh.pa.us> <20230403190837.qubpnwugfe2k2g46@awork3.anarazel.de> <7E06F879-7E20-4A6A-862F-CA72CDC9A323@yesql.se> <5028847C-937A-4CC2-B127-AFF5F9FB79C5@yesql.se> <2B703533-102A-47E5-A4F7-C6A68C09BB27@yesql.se> In-Reply-To: From: Melanie Plageman Date: Mon, 10 Apr 2023 20:16:12 -0400 Message-ID: Subject: Re: Should vacuum process config file reload more often To: Masahiko Sawada Cc: Daniel Gustafsson , Robert Haas , Andres Freund , Tom Lane , Kyotaro Horiguchi , PostgreSQL Hackers , Amit Kapila 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 Fri, Apr 7, 2023 at 9:07=E2=80=AFAM Melanie Plageman wrote: > > On Fri, Apr 7, 2023 at 2:53=E2=80=AFAM Masahiko Sawada wrote: > > > > On Fri, Apr 7, 2023 at 8:08=E2=80=AFAM Daniel Gustafsson wrote: > > > > > > > On 7 Apr 2023, at 00:12, Melanie Plageman wrote: > > > > > > > > On Thu, Apr 6, 2023 at 5:45=E2=80=AFPM Daniel Gustafsson wrote: > > > >> > > > >>> On 6 Apr 2023, at 23:06, Melanie Plageman wrote: > > > >> > > > >>> Autovacuum workers, at the end of VacuumUpdateCosts(), check if c= ost > > > >>> limit or cost delay have been changed. If they have, they assert = that > > > >>> they don't already hold the AutovacuumLock, take it in shared mod= e, and > > > >>> do the logging. > > > >> > > > >> Another idea would be to copy the values to local temp variables w= hile holding > > > >> the lock, and release the lock before calling elog() to avoid hold= ing the lock > > > >> over potential IO. > > > > > > > > Good idea. I've done this in attached v19. > > > > Also I looked through the docs and everything still looks correct f= or > > > > balancing algo. > > > > > > I had another read-through and test-through of this version, and have= applied > > > it with some minor changes to comments and whitespace. Thanks for th= e quick > > > turnaround times on reviews in this thread! > > > > Cool! > > > > Regarding the commit 7d71d3dd08, I have one comment: > > > > + /* Only log updates to cost-related variables */ > > + if (vacuum_cost_delay =3D=3D original_cost_delay && > > + vacuum_cost_limit =3D=3D original_cost_limit) > > + return; > > > > IIUC by default, we log not only before starting the vacuum but also > > when changing cost-related variables. Which is good, I think, because > > logging the initial values would also be helpful for investigation. > > However, I think that we don't log the initial vacuum cost values > > depending on the values. For example, if the > > autovacuum_vacuum_cost_delay storage option is set to 0, we don't log > > the initial values. I think that instead of comparing old and new > > values, we can write the log only if > > message_level_is_interesting(DEBUG2) is true. That way, we don't need > > to acquire the lwlock unnecessarily. And the code looks cleaner to me. > > I've attached the patch (use_message_level_is_interesting.patch) > > Thanks for coming up with the case you thought of with storage param for > cost delay =3D 0. In that case we wouldn't print the message initially an= d > we should fix that. > > I disagree, however, that we should condition it only on > message_level_is_interesting(). > > Actually, outside of printing initial values when the autovacuum worker > first starts (before vacuuming all tables), I don't think we should log > these values except when they are being updated. Autovacuum workers > could vacuum tons of small tables and having this print out at least > once per table (which I know is how it is on master) would be > distracting. Also, you could be reloading the config to update some > other GUCs and be oblivious to an ongoing autovacuum and get these > messages printed out, which I would also find distracting. > > You will have to stare very hard at the logs to tell if your changes to > vacuum cost delay and limit took effect when you reload config. I think > with our changes to update the values more often, we should take the > opportunity to make this logging more useful by making it happen only > when the values are changed. > > I would be open to elevating the log level to DEBUG1 for logging only > updates and, perhaps, having an option if you set log level to DEBUG2, > for example, to always log these values in VacuumUpdateCosts(). > > I'd even argue that, potentially, having the cost-delay related > parameters printed at the beginning of vacuuming could be interesting to > regular VACUUM as well (even though it doesn't benefit from config > reload while in progress). > > To fix the issue you mentioned and ensure the logging is printed when > autovacuum workers start up before vacuuming tables, we could either > initialize vacuum_cost_delay and vacuum_cost_limit to something invalid > that will always be different than what they are set to in > VacuumUpdateCosts() (not sure if this poses a problem for VACUUM using > these values since they are set to the defaults for VACUUM). Or, we > could duplicate this logging message in do_autovacuum(). > > Finally, one other point about message_level_is_interesting(). I liked > the idea of using it a lot, since log level DEBUG2 will not be the > common case. I thought of it but hesitated because all other users of > message_level_is_interesting() are avoiding some memory allocation or > string copying -- not avoiding take a lock. Making this conditioned on > log level made me a bit uncomfortable. I can't think of a situation when > it would be a problem, but it felt a bit off. > > > Also, while testing the autovacuum delay with relopt > > autovacuum_vacuum_cost_delay =3D 0, I realized that even if we set > > autovacuum_vacuum_cost_delay =3D 0 to a table, wi_dobalance is set to > > true. wi_dobalance comes from the following expression: > > > > /* > > * If any of the cost delay parameters has been set individuall= y for > > * this table, disable the balancing algorithm. > > */ > > tab->at_dobalance =3D > > !(avopts && (avopts->vacuum_cost_limit > 0 || > > avopts->vacuum_cost_delay > 0)); > > > > The initial values of both avopts->vacuum_cost_limit and > > avopts->vacuum_cost_delay are -1. I think we should use ">=3D 0" instea= d > > of "> 0". Otherwise, we include the autovacuum worker working on a > > table whose autovacuum_vacuum_cost_delay is 0 to the balancing > > algorithm. Probably this behavior has existed also on back branches > > but I haven't checked it yet. > > Thank you for catching this. Indeed this exists in master since > 1021bd6a89b which was backpatched. I checked and it is true all the way > back through REL_11_STABLE. > > Definitely seems worth fixing as it kind of defeats the purpose of the > original commit. I wish I had noticed before! > > Your fix has: > !(avopts && (avopts->vacuum_cost_limit >=3D 0 || > avopts->vacuum_cost_delay >=3D 0)); > > And though delay is required to be >=3D 0 > avopts->vacuum_cost_delay >=3D 0 > > Limit does not. It can just be > 0. > > postgres=3D# create table foo (a int) with (autovacuum_vacuum_cost_limit = =3D 0); > ERROR: value 0 out of bounds for option "autovacuum_vacuum_cost_limit" > DETAIL: Valid values are between "1" and "10000". > > Though >=3D is also fine, the rest of the code in all versions always > checks if limit > 0 and delay >=3D 0 since 0 is a valid value for delay > and not for limit. Probably best we keep it consistent (though the whole > thing is quite confusing). I have created an open item for each of these issues on the wiki (one for 16 and one under the section "affects stable branches"). - Melanie