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 1pXXwp-0000AB-Qu for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 01:41:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pXXwo-0007TD-NU for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 01:41:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pXXwo-0007T4-By for pgsql-hackers@lists.postgresql.org; Thu, 02 Mar 2023 01:41:30 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pXXwm-0008Pm-58 for pgsql-hackers@postgresql.org; Thu, 02 Mar 2023 01:41:29 +0000 Received: by mail-pj1-x102e.google.com with SMTP id m8-20020a17090a4d8800b002377bced051so1314441pjh.0 for ; Wed, 01 Mar 2023 17:41:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677721286; 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=jKuqjdEkZaPYV5r+2rz0TGXuZeumei3gdSCbmEO5uhA=; b=ar2kf7KoamWe2s3YKsH3bFB2ZVA1Ttmp8ybR7CR6wLqqS8wReWWj2z1tRELkc7ctUq OflHnSdoZAVk2gbNc7q9OdJevpk+RT32/91UaJzExodAbfKqQvSkskO58N9SAC9JM0NI KlCIA4cexmLc0kd+aE6o9gNSjWgaXnqjYkWS1s4+x3V4TKDRW26Zalu/rzALr3uw8dAq ZWANYK+BcRWy/p1KHK8++KT1hd2lM/FKWgJ22lRNjmAv6nVg+yNJMZ0Il5TBkGcN/5WY 56A2aOa9ptrfrQvtH++xj3taoG4Zd2Pxq+MS/DkugDKsKW7379jrXwdexhV5y8VEVt/v khIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677721286; 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=jKuqjdEkZaPYV5r+2rz0TGXuZeumei3gdSCbmEO5uhA=; b=u+lB0W2uhOVYQ7zilTVnWL2723m1ZYmHPUPIBfPtXRNaBODHdRvyJbhzXo4BzMMn6l 639rh4OCDTwa89yb+5PkhvAYYXXuQwAUTnYvA/dZbD9DNXpncI3px8tX48QADnAA1R0A aAXJXXxRyfwC0PY+SA75Fgqx8S7+Jlq9AgQVouPZZFK6XlcCrHur1eyXA+3ZTRj2FfcT K3BOyDjH8u5mEpAfe6GCF4z97G9QnBqG+YNgB1uB8TAWhdMH7wSTT/C7jzPdpa5DFV70 OlNSZe1SLb11JUGxU1i1Cw1Ln55G8qrnp4Iiv26/E3b2Sazcj5Sr7uY7tlTg8+AaN/qc tXFg== X-Gm-Message-State: AO0yUKVnVL0IUP0UQ+7TqLHrA+Ok6grrXjOjvPrKlIfRMfqGLNlSTqdO pXQE/Pfz/HcJOPnXHTSrZQRws18syJduYjrVKUc= X-Google-Smtp-Source: AK7set+dWy2iXWOgG1MdLcpwqz9E/4q7mnn/Ly57Oc+IF4HouSM9lf2TQX6MaipnB0ZNlfzk+dRBfWDJMyYHMAiVOUc= X-Received: by 2002:a17:90a:ae16:b0:22c:89b:5a8d with SMTP id t22-20020a17090aae1600b0022c089b5a8dmr3364638pjq.6.1677721285799; Wed, 01 Mar 2023 17:41:25 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Melanie Plageman Date: Wed, 1 Mar 2023 20:41:14 -0500 Message-ID: Subject: Re: Should vacuum process config file reload more often To: Masahiko Sawada 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 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 the > > 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 ConfigReloadPending > > 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 necess= ary. 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 w= rote: > On 2023-02-28 11:16:45 +0900, Masahiko Sawada wrote: > > On Tue, Feb 28, 2023 at 10:21 AM Andres Freund wro= te: > > > On 2023-02-27 23:11:53 +0900, Masahiko Sawada wrote: > > > > Also, I'm concerned that allowing to change any GUC parameters duri= ng > > > > vacuum/analyze could be a foot-gun in the future. When modifying > > > > vacuum/analyze-related codes, we have to consider the case where an= y 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 t= he > config can be changed in a more granular way, doesn't mean we have to rea= ct 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 pro= bably isn't needed. 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. I started writing a little helper that could be used to update these workerinfo->wi_cost_delay/limit in vacuum_delay_point(), 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 - Melanie