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 1jEvrz-0004Mx-Tt for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2020 14:10:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jEvry-0004Vk-Dv for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2020 14:09:58 +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 1jEvrx-0004Vc-VU for pgsql-hackers@lists.postgresql.org; Thu, 19 Mar 2020 14:09:58 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jEvrq-0007s2-7x for pgsql-hackers@lists.postgresql.org; Thu, 19 Mar 2020 14:09:56 +0000 Received: by mail-qt1-x842.google.com with SMTP id l20so1864586qtp.4 for ; Thu, 19 Mar 2020 07:09:49 -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=eZV3md3k3ibzNt8svK2rAi7p7TCp1Po9fDnFD+kHVyk=; b=Z/OZJ1NpAEm69dMoUlMvNk+ZS3DfYHb4LFvAQlnPHVbueXA2g7O1CnLk3e4TY6SI4C VLSslhCtWvhlWH6fmIcwWuPjwn0sQzBn9c0diYiPEpEi7RdF2DVYkC0X8FbJkvsneYt0 I+1nJbDoeBOrD4InaR5AMpikH4Pp4g4JVLvpx693pX/hc49WNIMNhYWAn94SqRlYIUsg SuUXTB3MDbL901Cc+3C4lf/4o0eY4Ae/S0ERSO7ZopnxBC5XIAdR0YXdOODthC0D5Dvl oZRBxJkF+u2U0wjCC/Je+/42Ies0Htb3WBtC3BfLljgmwPWuW1mCixpYZuaGY29JTBLV 8K0g== 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=eZV3md3k3ibzNt8svK2rAi7p7TCp1Po9fDnFD+kHVyk=; b=KYFXriRrBF0mzkoj6LzG9XiFMkKejUPxP6oGUjXzK20b9JQmjIw1tpJcQ9KLwgPOmj DEwk8nKiJMBZh/8Blv8nnV4pUwUglU59K0ZbmL2dk4cye0vcKoZoPkMx9vI6mRtJgGJ8 8cQRvrOD35s7164k/xDrb7zKCXRFsyi3fOS6ikJzZk2AjPsJOFRW1EXj/FAvHmtqPuDl ZpVQhZ039kbQ3zYD507yhHhnbDXmYwvAVUtfRzztDL5BTWHOVOYB+j7RBCeytbf6bu4O PcRUK5CXKaZAAlLuWTGP3j82kBWHSfHK6mxf0+OKHBfeZAUgyoXDZT215+TJJ1v/1+mD g99w== X-Gm-Message-State: ANhLgQ0WXoqJlB9xhCQZznj/HFHYyY5NHNVcWhS+fQGrUiP1UqJxdsqm KzUOvRWrxMy+Ulago5ln5jrQBQ== X-Google-Smtp-Source: ADFU+vutW/4BI7fayVXJCYmnwpbhulaTwAiJ7oO3nEHBlcz9oCqaJWG1xjHqZJDyKbskEhc88bjLew== X-Received: by 2002:aed:2533:: with SMTP id v48mr3163749qtc.39.1584626988482; Thu, 19 Mar 2020 07:09:48 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a186sm1613036qkg.2.2020.03.19.07.09.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2020 07:09:47 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id A2C10800CF1; Thu, 19 Mar 2020 09:09:45 -0500 (CDT) Date: Thu, 19 Mar 2020 09:09:45 -0500 From: Justin Pryzby To: David Rowley Cc: Andres Freund , Laurenz Albe , Tomas Vondra , Amit Kapila , Masahiko Sawada , Darafei =?utf-8?Q?Kom=D1=8Fpa?= Praliaskouski , pgsql-hackers@lists.postgresql.org, Alvaro Herrera , Michael Banck Subject: Re: Berserk Autovacuum (let's save next Mandrill) Message-ID: <20200319140945.GS26184@telsasoft.com> References: <602873766faa0e9200a60dcc26dc10c636761d5d.camel@cybertec.at> <91c110aad4b8653d6433d42fd707bd16074c79a5.camel@cybertec.at> <20200313184442.GS29065@telsasoft.com> <20200313213851.ejrk5gptnmp65uoo@alap3.anarazel.de> <20200319060658.GQ26184@telsasoft.com> 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 Thu, Mar 19, 2020 at 09:52:11PM +1300, David Rowley wrote: > On Thu, 19 Mar 2020 at 19:07, Justin Pryzby wrote: > > > > On Fri, Mar 13, 2020 at 02:38:51PM -0700, Andres Freund wrote: > > > On 2020-03-13 13:44:42 -0500, Justin Pryzby wrote: > > > > Having now played with the patch, I'll suggest that 10000000 is too high a > > > > threshold. If autovacuum runs without FREEZE, I don't see why it couldn't be > > > > much lower (100000?) or use (0.2 * n_ins + 50) like the other autovacuum GUC. > > > > > > ISTM that the danger of regressing workloads due to suddenly repeatedly > > > scanning huge indexes that previously were never / rarely scanned is > > > significant (if there's a few dead tuples, otherwise most indexes will > > > be able to skip the scan since the vacuum_cleanup_index_scale_factor > > > introduction)). > > > > We could try to avoid that issue here: > > > > | /* If any tuples need to be deleted, perform final vacuum cycle */ > > | /* XXX put a threshold on min number of tuples here? */ > > | if (dead_tuples->num_tuples > 0) > > | { > > | /* Work on all the indexes, and then the heap */ > > | lazy_vacuum_all_indexes(onerel, Irel, indstats, vacrelstats, > > | lps, nindexes); > > | > > | /* Remove tuples from heap */ > > | lazy_vacuum_heap(onerel, vacrelstats); > > | } > > > > As you said, an insert-only table can skip scanning indexes, but an > > insert-mostly table currently cannot. > > > > Maybe we could skip the final index scan if we hit the autovacuum insert > > threshold? > > > > I still don't like mixing the thresholds with the behavior they imply, but > > maybe what's needed is better docs describing all of vacuum's roles and its > > procedure and priority in executing them. > > > > The dead tuples would just be cleaned up during a future vacuum, right ? So > > that would be less efficient, but (no surprise) there's a balance to strike and > > that can be tuned. I think that wouldn't be an issue for most people; the > > worst case would be if you set high maint_work_mem, and low insert threshold, > > and you got increased bloat. But faster vacuum if we avoided idx scans. > > > > That might allow more flexibility in our discussion around default values for > > thresholds for insert-triggered vacuum. > > We went over this a bit already. The risk is that if you have an > insert-mostly table and always trigger an auto-vacuum for inserts and > never due to dead tuples, then you'll forego the index cleanup every > time causing the indexes to bloat over time. At the time, we were talking about skipping index *cleanup* phase. Which also incurs an index scan. >+ tab->at_params.index_cleanup = insert_only ? VACOPT_TERNARY_DISABLED : VACOPT_TERNARY_DEFAULT; We decided not to skip this, since it would allow index bloat, if vacuum were only ever run due to inserts, and cleanup never happened. I'm suggesting the possibility of skipping not index *cleanup* but index (and heap) *vacuum*. So that saves an index scan itself, and I think implies later skipping cleanup (since no index tuples were removed). But more importantly, I think if we skip that during an insert-triggered vacuum, the dead heap tuples are still there during the next vacuum instance. So unlike index cleanup (where we don't keep track of the total number of dead index tuples), this can accumulate over time, and eventually trigger index+heap vacuum, and cleanup. > I think any considerations to add some sort of threshold on dead > tuples before cleaning the index should be considered independently. +1, yes. I'm hoping to anticipate and mitigate any objections and regressions more than raise them. -- Justin