Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jDp9X-00011I-4K for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2020 12:47:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jDp9V-0007jQ-K4 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2020 12:47:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jDp9V-0007jI-6o for pgsql-hackers@lists.postgresql.org; Mon, 16 Mar 2020 12:47:29 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jDp9M-0003Dz-PF for pgsql-hackers@lists.postgresql.org; Mon, 16 Mar 2020 12:47:28 +0000 Received: by mail-qk1-x744.google.com with SMTP id s11so14491553qks.8 for ; Mon, 16 Mar 2020 05:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ktn0Bhv1giXNVma8Z2/BXgytbDzdabXnjL7ulIougOE=; b=N8S238+yG7hJmxNEUCJccFwGVFOZ7NrzsW4IgQ0y6SYnzt5w6FFt5lbBSSKWSmqrdZ XvtdVwh8J+b7S4po4QzCumrVwcwDUMmRgTnGJig5Ot0eKHkp7LEly3VA3VraLKWuSjiQ 905DlxJhLm4YRSe3x5yWaAjwocSMCvrL71AwFS442bG1Q9aeMSXxqe1/z8gHHUM2kGCW WIE6XKxuqT7rRbIlkuTyAtnWcFbVqIO0dCtJzIi9WP10BE77g//v47139WqhuxcQSAUM qe2qGeLJ4Hc0svmhwj8Vaz9cFGrk+atsBxFPAd1K5h9iTH8BEunE4vVWbZbhdWvmtCQ/ j8vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ktn0Bhv1giXNVma8Z2/BXgytbDzdabXnjL7ulIougOE=; b=AuZoSL073Flm0YbYta3NbJ+By4bvWR/pZ59TvkBroilf62MLQcxT5TDZsjTSyyBRqW BdwOJGJ+h7plrsNNbrYAU7l5wHoATmaiBxQ1Z5pCwO7WBrvhVjqVAl9q1CZ95hZj6jXn +AsAqQDyVv9D7rTG4ReHA29KyLN1NvMtVrg5G/nWTC7DNa3FuIdco3iQODT1lqcmyeyo fMcYiia5AgpdMtdIyGTnOPidZenILQra5NXAm+GTxzj1ah4zt56k/I+5JxgarvBwsxxL QONWoGOt7b9z0xrtmwM7c//+uMSPLt+EX3TrSsuKFEEQmWvE91bVad1DGqqjgoKRVhUV e/RQ== X-Gm-Message-State: ANhLgQ2eTr4RZ4kUWskg+NtX5z8jvAHdo5mdd5Kslsr/QMEX1dqD47N4 4ran5vhVuIxvnNcJpOIcaSMUcw== X-Google-Smtp-Source: ADFU+vu/TV92juyEORvkmkKYh2oYK9nWvXwNhjo4mZhs7UnsIPmW1fU7oenYFy9fsWRNw+MWNQnK/g== X-Received: by 2002:a37:9a81:: with SMTP id c123mr26000845qke.176.1584362836511; Mon, 16 Mar 2020 05:47:16 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id u40sm4528445qtc.62.2020.03.16.05.47.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Mar 2020 05:47:15 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id EE7B5800F5B; Mon, 16 Mar 2020 07:47:13 -0500 (CDT) Date: Mon, 16 Mar 2020 07:47:13 -0500 From: Justin Pryzby To: Masahiko Sawada Cc: David Rowley , Laurenz Albe , Tomas Vondra , Amit Kapila , Masahiko Sawada , Darafei =?utf-8?Q?Kom=D1=8Fpa?= Praliaskouski , Andres Freund , PostgreSQL Developers , Alvaro Herrera , Michael Banck Subject: Re: Berserk Autovacuum (let's save next Mandrill) Message-ID: <20200316124713.GH26184@telsasoft.com> References: <9c312999bb8e0495b88d1422980ecc0abc1b1b86.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Mar 16, 2020 at 12:53:43PM +0900, Masahiko Sawada wrote: > There is already a consensus on introducing new 2 parameters, but as > the second idea I'd like to add one (or two) GUC(s) to my suggestion, > say autovacuum_vacuum_freeze_insert_ratio; this parameter is the ratio > of the number of inserted tuples for total number of tuples modified > and inserted, in order to trigger insert-only vacuum. For example, > suppose the table has 1,000,000 tuples and we set threshold = 0, > scale_factor = 0.2 and freeze_insert_ratio = 0.9, we will trigger > normal autovacuum when n_dead_tup + n_ins_since_vacuum > 200,000, but > we will instead trigger insert-only autovacuum, which is a vacuum with > vacuum_freeze_min_age = 0, when n_ins_since_vacuum > 180,000 (=200,000 > * 0.9). IOW if 90% of modified tuples are insertions, we freeze tuples > aggressively. If we want to trigger insert-only vacuum only on > insert-only table we can set freeze_insert_ratio = 1.0. The down side > of this idea is that we cannot disable autovacuum triggered by the > number of inserted, although we might be able to introduce more one > GUC that controls whether to include the number of inserted tuples for > triggering autovacuum (say, autovacuum_vacuum_triggered_by_insert = > on|off). The pros of this idea would be that we can ensure that > insert-only vacuum will run only in the case where the ratio of > insertion is large enough. I was thinking about something like this myself. I would appreciate keeping separate the thresholds for 1) triggering vacuum; and, 2) the options autovacuum uses when it runs (in this case, FREEZE). Someone might want autovacuum to run with FREEZE on a table vacuumed due to dead tuples (say, on a partitioned table), or might *not* want to run FREEZE on a table vacuumed due to insertions (maybe because index scans are too expensive or FREEZE makes it too slow). Normally, when someone complains about bad plan related to no index-onlyscan, we tell them to run vacuum, and if that helps, then ALTER TABLE .. SET (autovacuum_vacuum_scale_factor=0.005). If there's two thresholds (4 GUCs and 4 relopts) for autovacuum, then do we have to help determine which one was being hit, and which relopt to set? I wonder if the new insert GUCs should default to -1 (disabled)? And the insert thresholds should be set by new insert relopt (if set), or by new insert GUC (default -1), else normal relopt, or normal GUC. The defaults would give 50 + 0.20*n. When someone asks about IOS, we'd tell them to set autovacuum_vacuum_scale_factor=0.005, same as now. vac_ins_scale_factor = (relopts && relopts->vacuum_ins_scale_factor >= 0) ? relopts->vacuum_ins_scale_factor : autovacuum_vac_ins_scale >= 0 ? autovacuum_vac_ins_scale : (relopts && relopts->vacuum_scale_factor >= 0) ? relopts->vacuum_scale_factor : autovacuum_vac_scale; One would disable autovacuum triggered by insertions by setting autovacuum_vacuum_insert_scale_factor=1e10 (which I think should also be the max for this patch). It seems to me that the easy thing to do is to implement this initially without FREEZE (which is controlled by vacuum_freeze_table_age), and defer until July/v14 further discussion and implementation of another GUC/relopt for autovacuum freezing to be controlled by insert thresholds (or ratio). -- Justin