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 1pXsUx-0005Xp-3W for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 23:38:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pXsUv-0006ii-Hg for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 23:38:05 +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 1pXsUv-0006iZ-67 for pgsql-hackers@lists.postgresql.org; Thu, 02 Mar 2023 23:38:05 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pXsUn-0004Qx-S8 for pgsql-hackers@postgresql.org; Thu, 02 Mar 2023 23:38:03 +0000 Received: by mail-pf1-x433.google.com with SMTP id cp12so509572pfb.5 for ; Thu, 02 Mar 2023 15:37:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677800275; 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=vxK5Eg3GrwuJBlrdVh4nse8gznnmItxd8wdZ3Ed40Cg=; b=DrQkzBmo3pUKgQIz4IiR3tUaPp6Z3iYjK5ib9ysEibCXx28c9IhWVfFJEANGUysioM mQulZlWLN8XS7clU/ser1vMmAaVgPBZa/roRMHCKCZX3TgMuTKZtWuL6vM0WspruKbMl WKMyKnGQBCr1r0RLwCAXOyD+rdSghvE5fJG6cvwDumokT/is5XJ4QWE5HFvESFkIkjZP ewT8peTegp0JdFORavrwFJvYaEAA13zWIq5pFkIdM3uSYXiC3X+jzpEAE5o1UzPV8DAi YbwojPG2a5rfexVv886ubTS8sJn3RVmegVs5P0DkeEKq1tWX4nUiI+O0sTY8WIjKOXmY U+Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677800275; 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=vxK5Eg3GrwuJBlrdVh4nse8gznnmItxd8wdZ3Ed40Cg=; b=t85kclNbTb3q3saklUVbfS5NgQMFJJ3GMafBMvDEfXSKaFvax+vdFZrg/WC4VP6d1p i5nkth6039EhWysR9L7CNUCsjptmt0wkbwWqvtM23jI1SyuSMXuHoyYvdrLE3YbaHnpX n+1SCtW4S957dJtLkx9f1IuHOErxXndLEmL+9uz0WNJdmbF3wLG3cJqzRFyEduU0IZjS 2IvfroXWeYG1sy9+YgyqusITPUeTzoeCfwhOERijzSc0yrss77ZWEkAKdHS3o5Q+QtE/ XEpuLIefWyXzK8aGSYgnD/kSdhbQkw/ahrv1Z3Sj5n9Wtm4Y05QzuLI+nV++/IB9vn7l FjHw== X-Gm-Message-State: AO0yUKU+nNHO21UPNuHTM/hAJwEd+VbOsgHa6ugqBkZAzXQmXlU3K6f5 Hf0CEqmNpryAHAVm4nz3feeleoj5pJk3EbYELNU= X-Google-Smtp-Source: AK7set/+maygHTLgtkpBlhl7HZfMbZKEwRkWVp4AXxRzBU64eR8r4uCcrsUDvYrkmHsXg0CN4ezWnbfcxmXoy90oGck= X-Received: by 2002:a63:7413:0:b0:502:fd12:83d2 with SMTP id p19-20020a637413000000b00502fd1283d2mr4001178pgc.8.1677800274704; Thu, 02 Mar 2023 15:37:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Melanie Plageman Date: Thu, 2 Mar 2023 18:37:43 -0500 Message-ID: Subject: Re: Should vacuum process config file reload more often To: Masahiko Sawada Cc: Pg Hackers , Andres Freund , 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 Thu, Mar 2, 2023 at 2:36=E2=80=AFAM Masahiko Sawada wrote: > > On Thu, Mar 2, 2023 at 10:41 AM Melanie Plageman > wrote: > > 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. Ah yes, I didn't realize this. Thanks. I went back and did more code reading/analysis, and I see no reason why we shouldn't update worker->wi_cost_delay to the new value of autovacuum_vac_cost_delay in autovac_balance_cost(). Then, as you said, the autovac launcher will call autovac_balance_cost() when it reloads the configuration file. Then, the next time the autovac worker calls AutoVacuumUpdateDelay(), it will update VacuumCostDelay. > > 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. Yes, agreed, it should go in the same place as where we update wi_cost_limit (autovac_balance_cost()). I think we should potentially rename autovac_balance_cost() because its name and all its comments point to its only purpose being to balance the total of the workers wi_cost_limits to no more than autovacuum_vacuum_cost_limit. And the autovacuum_vacuum_cost_delay doesn't need to be balanced in this way. Though, since this change on its own would make autovacuum pick up new values of autovacuum_vacuum_cost_limit (without having the worker reload the config file), I wonder if it makes sense to try and have vacuum_delay_point() only reload the config file if it is an explicit vacuum or an analyze not being run in an outer transaction (to avoid overhead of reloading config file)? The lifecycle of this different vacuum delay-related gucs and how it differs between autovacuum workers and explicit vacuum is quite tangled already, though. > > 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 f= or > * 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. Yes, if the table has autovacuum table options, I think the user is out-of-luck until the relation is done being vacuumed because the ALTER TABLE will need to get a lock. - Melanie