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 1pXdUj-0000Qj-EQ for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 07:36:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pXdUi-0008VS-7u for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 07:36:52 +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 1pXdUh-0008V8-N9 for pgsql-hackers@lists.postgresql.org; Thu, 02 Mar 2023 07:36:51 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pXdUc-0006V7-CZ for pgsql-hackers@postgresql.org; Thu, 02 Mar 2023 07:36:50 +0000 Received: by mail-ot1-x32f.google.com with SMTP id g6-20020a056830308600b0068d4b30536aso9016968ots.9 for ; Wed, 01 Mar 2023 23:36:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=K1a9dZ/fUFbfpmYAZtQKdcZQLAC4Kw7+LTR18JRgGR8=; b=YKaYfIRGrTw72xmtMJknKgWK4G2RUXL1ePSBeJ2V5uFBzY3FbrYCLIvtwXCrULMHPo o12PZRcIC9+nJ/XXtASjnmu0X2IhGL9EuEscMvY/VMFlAb7oAyqPgvNlBzNW+gKXeqJD /5E9KETqQJ4PIJq+ZVS9oQt1PtKDIJhS4Wp0Rqrhv+dOa6LEUOGwkPnb5Bcq9J8KxCTm GpPHOmafCUVfyjB/n6pxJGrACeS6bxC9juBpsuF0PKg6FOciLds1EE83Wh3xokx6mlmU 855hKKI03pjJ2A/BBgi3W5SRMsLIV61wekElpHOG2lqfbzUG0WD0QncstDXrmLPFJJj2 CEmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=K1a9dZ/fUFbfpmYAZtQKdcZQLAC4Kw7+LTR18JRgGR8=; b=KJT/pXhZ5v69Xe5gf+lbrwSQS6D+1J0TPhF4tmnY0598RayBciV+LkcbzV05mQpOOq /4VxIrBV8v+R7ozqL7YkiRJ1bwli3lGJ6OizndbL+b+Ki9jagTqJFzDhhNYVurw3t2po SMnIxovRtUE0Q5+dzFdYU2hPBFXB940QWoufSv0dcHHELgRybbW2Q6jPdcyqLBTi4++v HGB0P/iE9dTurtHqpOmM0l34TN0yUPmhLFjOCcq7CLJavnWtE/R6mXZGtHPLW4pTxXD3 /jJV9mj+TQpHnzVptMWd3Jh80XBmA7xafL9rXE1YVTaz+oxD1N4Z/WDEFzmN49YZUudE u69Q== X-Gm-Message-State: AO0yUKUICT27TH8UHhT1D0eQ+efdH8rs1ob1z/RuGz5WfW5hhD0rX/21 izh0fOQORYDZlphCzk9HAYEbM5Lhvo4/bqKDauv8MiIqELE= X-Google-Smtp-Source: AK7set/a/Agq/bezgBBnKj8VmvdUxsxzQOU3hnbMIGJzDzllAW0iZcpbS/lbL8JKaIOdRjlXH/+6biTvlhzNkKmWzu8= X-Received: by 2002:a9d:62a:0:b0:68d:4b7f:e993 with SMTP id 39-20020a9d062a000000b0068d4b7fe993mr3126527otn.3.1677742605296; Wed, 01 Mar 2023 23:36:45 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Thu, 2 Mar 2023 16:36:09 +0900 Message-ID: Subject: Re: Should vacuum process config file reload more often To: Melanie Plageman Cc: Pg Hackers , Andres Freund 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 Thu, Mar 2, 2023 at 10:41 AM Melanie Plageman wrote: > > On Mon, Feb 27, 2023 at 9:12=E2=80=AFAM Masahiko Sawada wrote: > > On Fri, Feb 24, 2023 at 7:08 AM Melanie Plageman > > wrote: > > > Users may wish to speed up long-running vacuum of a large table by > > > decreasing autovacuum_vacuum_cost_delay/vacuum_cost_delay, however th= e > > > config file is only reloaded between tables (for autovacuum) or after > > > the statement (for explicit vacuum). This has been brought up for > > > autovacuum in [1]. > > > > > > Andres suggested that it might be possible to check ConfigReloadPendi= ng > > > in vacuum_delay_point(), so I thought I would draft a rough patch and > > > start a discussion. > > > > In vacuum_delay_point(), we need to update VacuumCostActive too if nece= ssary. > > Yes, good point. Thank you! > > On Thu, Feb 23, 2023 at 5:08=E2=80=AFPM Melanie Plageman > wrote: > > I don't think I can set and leave vac_in_outer_xact the way I am doing > > it in this patch, since I use vac_in_outer_xact in vacuum_delay_point()= , > > which I believe is reachable from codepaths that would not have called > > vacuum(). It seems that if a backend sets it, the outer transaction > > commits, and then the backend ends up calling vacuum_delay_point() in a > > different way later, it wouldn't be quite right. > > Perhaps I could just set in_outer_xact to false in the PG_FINALLY() > section in vacuum() to avoid this problem. > > On Wed, Mar 1, 2023 at 7:15=E2=80=AFPM Andres Freund = wrote: > > On 2023-02-28 11:16:45 +0900, Masahiko Sawada wrote: > > > On Tue, Feb 28, 2023 at 10:21 AM Andres Freund w= rote: > > > > On 2023-02-27 23:11:53 +0900, Masahiko Sawada wrote: > > > > > Also, I'm concerned that allowing to change any GUC parameters du= ring > > > > > vacuum/analyze could be a foot-gun in the future. When modifying > > > > > vacuum/analyze-related codes, we have to consider the case where = any GUC > > > > > parameters could be changed during vacuum/analyze. > > > > > > > > What kind of scenario are you thinking of? > > > > > > For example, I guess we will need to take care of changes of > > > maintenance_work_mem. Currently we initialize the dead tuple space at > > > the beginning of lazy vacuum, but perhaps we would need to > > > enlarge/shrink it based on the new value? > > > > I don't think we need to do anything about that initially, just because= the > > config can be changed in a more granular way, doesn't mean we have to r= eact to > > every change for the current operation. > > Perhaps we can mention in the docs that a change to maintenance_work_mem > will not take effect in the middle of vacuuming a table. But, Ithink it p= robably > isn't needed. Agreed. > > On another topic, I've just realized that when autovacuuming we only > update tab->at_vacuum_cost_delay/limit from > autovacuum_vacuum_cost_delay/limit for each table (in > table_recheck_autovac()) and then use that to update > MyWorkerInfo->wi_cost_delay/limit. MyWorkerInfo->wi_cost_delay/limit is > what is used to update VacuumCostDelay/Limit in AutoVacuumUpdateDelay(). > So, even if we reload the config file in vacuum_delay_point(), if we > don't use the new value of autovacuum_vacuum_cost_delay/limit it will > have no effect for autovacuum. Right, but IIUC wi_cost_limit (and VacuumCostDelayLimit) might be updated. After the autovacuum launcher reloads the config file, it calls autovac_balance_cost() that updates that value of active workers. I'm not sure why we don't update workers' wi_cost_delay, though. > I started writing a little helper that could be used to update these > workerinfo->wi_cost_delay/limit in vacuum_delay_point(), Since we set vacuum delay parameters for autovacuum workers so that we ration out I/O equally, I think we should keep the current mechanism that the autovacuum launcher sets workers' delay parameters and they update accordingly. > but I notice > when they are first set, we consider the autovacuum table options. So, > I suppose I would need to consider these when updating > wi_cost_delay/limit later as well? (during vacuum_delay_point() or > in AutoVacuumUpdateDelay()) > > I wasn't quite sure because I found these chained ternaries rather > difficult to interpret, but I think table_recheck_autovac() is saying > that the autovacuum table options override all other values for > vac_cost_delay? > > vac_cost_delay =3D (avopts && avopts->vacuum_cost_delay >=3D 0) > ? avopts->vacuum_cost_delay > : (autovacuum_vac_cost_delay >=3D 0) > ? autovacuum_vac_cost_delay > : VacuumCostDelay; > > i.e. this? > > if (avopts && avopts->vacuum_cost_delay >=3D 0) > vac_cost_delay =3D avopts->vacuum_cost_delay; > else if (autovacuum_vac_cost_delay >=3D 0) > vac_cost_delay =3D autovacuum_vacuum_cost_delay; > else > vac_cost_delay =3D VacuumCostDelay Yes, if the table has autovacuum table options, we use these values and the table is excluded from the balancing algorithm I mentioned above. See the code from table_recheck_autovac(), /* * If any of the cost delay parameters has been set individually for * this table, disable the balancing algorithm. */ tab->at_dobalance =3D !(avopts && (avopts->vacuum_cost_limit > 0 || avopts->vacuum_cost_delay > 0)); So if the table has autovacuum table options, the vacuum delay parameters probably should be updated by ALTER TABLE, not by reloading the config file. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com