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 1jEPW4-0005DC-Ck for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Mar 2020 03:37:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jEPW3-0005Ay-3O for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Mar 2020 03:37:11 +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 1jEPW2-00058a-LF for pgsql-hackers@lists.postgresql.org; Wed, 18 Mar 2020 03:37:10 +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 1jEPVy-00053A-5I for pgsql-hackers@lists.postgresql.org; Wed, 18 Mar 2020 03:37:09 +0000 Received: by mail-qk1-x744.google.com with SMTP id s11so25220342qks.8 for ; Tue, 17 Mar 2020 20:37:06 -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=isCo6GeotLYPwIPANyFHxUjEj2yMxPeRQhEYT05tfUE=; b=a3aeyH8kjWpQ5Ss3v2dYQSAw7qNo1IXCStg831mCPshe1e0XyPjsz1Gt3FXlc1I7i3 0Er7MClmzAYwPEhY7YSaIKwNWky/vCBPvgbdkj+ScRoCafnuim+Nk2L01JkQcRqhwhCJ 8/3DmOT+zxNNxVuKj2u7nCoy0hmQk8351CozNTI/GLbF1OakglkZeb0swFtmkGXBXGTA qkUOOkYjrF2nbHcLo57E8MPQyHvrGxc7I4Kn6ULy6S4CbWkaXTX3SBMJQ+3qNoqZ3jgE 0w3iskHp9PUWZI+BEsm7vyjUcQlmI3VT1OiXgMK935xM/faekBcZqH5dgTmUkY087KWr 9PpA== 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=isCo6GeotLYPwIPANyFHxUjEj2yMxPeRQhEYT05tfUE=; b=ZYzEtPH3H8Zk6BA1NDN86qeFdlhP3Ab5FqbTvEi4X1mZzPtyvF2Hfwo7IoIMBpdgDT SCWfh1bXmuzu7ej0OCAUCnZDwfyPWqE0yl+L3O7baQfAc0KTA6P+boYi8dQS92jPhVsg DMCiJ8oE3EYR2i+Po5MopUqlVHUlPNtgl23W6pfDPdfIOwWOVSFggXTuSnbHpDsnxwnV izWfkPfX87qeR4EuwQYCitfRaMBxdO3hmfTZbJsx2Kn1tZ8l+/1D08xNyh0glqY40V14 DlcViIJ2dk/V3rOmA2OwkHWxySOfOQnXfgKWlxPj6qSQmXztriIvbOpfT2dAST64YV2R OqTA== X-Gm-Message-State: ANhLgQ10vkCi+TmSNWVsWoiTvpoAAEVG+c6E1Tl7cHtHREX9Thq5Ql9E 6iJYqPsioqOZLfmj+FCynPSfEQ== X-Google-Smtp-Source: ADFU+vtWuVorSXyvlsybRL2gok5+IL/n8tcQ0wZQNKsEqOKpU2O++ghNxR47fbpril35Syheqt2qEw== X-Received: by 2002:a05:620a:2117:: with SMTP id l23mr2068126qkl.323.1584502624419; Tue, 17 Mar 2020 20:37:04 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id p35sm3891326qtk.2.2020.03.17.20.37.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Mar 2020 20:37:03 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id DA0DF800CF1; Tue, 17 Mar 2020 22:37:01 -0500 (CDT) Date: Tue, 17 Mar 2020 22:37:01 -0500 From: Justin Pryzby To: James Coleman Cc: Andres Freund , Laurenz Albe , Masahiko Sawada , David Rowley , 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: <20200318033701.GF26184@telsasoft.com> References: <20200316124713.GH26184@telsasoft.com> <9c9b7d19d17ad5e4e0ee10b8426fa1b78dd24c0a.camel@cybertec.at> <20200316201315.dgkeedl6rp2wdjje@alap3.anarazel.de> <19be41199e7b303bbecc1066bd9f011d95882aa8.camel@cybertec.at> <20200316213459.kh6xln3z35hgjodd@alap3.anarazel.de> <7c132215f0e947af7d9ccb7a340ad6e81b369c24.camel@cybertec.at> <20200317152409.GW26184@telsasoft.com> <20200318010254.sra6fldiqz7ey6is@alap3.anarazel.de> 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 Tue, Mar 17, 2020 at 09:58:53PM -0400, James Coleman wrote: > On Tue, Mar 17, 2020 at 9:03 PM Andres Freund wrote: > > > > On 2020-03-17 20:42:07 +0100, Laurenz Albe wrote: > > > > I think Andres was thinking this would maybe be an optimization independent of > > > > is_insert_only (?) > > > > > > I wasn't sure. > > > > I'm not sure myself - but I'm doubtful that using a 0 min age by default > > will be ok. > > > > I was trying to say (in a later email) that I think it might be a good > > compromise to opportunistically freeze if we're dirtying the page > > anyway, but not optimize WAL emission etc. That's a pretty simple > > change, and it'd address a lot of the potential performance regressions, > > while still freezing for the "first" vacuum in insert only workloads. > > If we have truly insert-only tables, then doesn't vacuuming with > freezing every tuple actually decrease total vacuum cost (perhaps > significantly) since otherwise every vacuum keeps having to scan the > heap for dead tuples on pages where we know there are none? Those > pages could conceptually be frozen and ignored, but are not frozen > because of the default behavior, correct? The essential part of this patch is to trigger vacuum *at all* on an insert-only table. Before today's updated patch, it also used FREEZE on any table which hit the new insert threshold. The concern I raised is for insert-MOSTLY tables. I thought it might be an issue if repeatedly freezing updated tuples caused vacuum to be too slow, especially if they're distributed in pages all across the table rather than clustered. And I asked that the behavior (FREEZE) be configurable by a separate setting than the one that triggers autovacuum to run. FREEZE is already controlled by the vacuum_freeze_table_age param. I think you're right that VACUUM FREEZE on an insert-only table would be less expensive than vacuum once without freeze and vacuum again later, which uses freeze. To me, that suggests setting vacuum_freeze_table_age to a low value on those tables. Regular vacuum avoids scanning all-visible pages, so for an insert-only table pages should only be vacuumed once (if frozen the 1st time) or twice (if not). * Except when aggressive is set, we want to skip pages that are * all-visible according to the visibility map, but only when we can skip postgres=# CREATE TABLE t (i int) ; INSERT INTO t SELECT generate_series(1,999999); VACUUM VERBOSE t; VACUUM VERBOSE t; ... INFO: "t": found 0 removable, 999999 nonremovable row versions in 4425 out of 4425 pages ... VACUUM Time: 106.038 ms INFO: "t": found 0 removable, 175 nonremovable row versions in 1 out of 4425 pages VACUUM Time: 1.828 ms => That's its not very clear way of saying that it only scanned 1 page the 2nd time around. > We have tables that log each change to a business object (as I suspect > many transactional workloads do), and I've often thought that > immediately freeze every page as soon as it fills up would be a real > win for us. > > If that's all true, it seems to me that removing that part of the > patch significantly lowers its value. > If we opportunistically freeze only if we're already dirtying a page, > would that help a truly insert-only workload? E.g., are there hint > bits on the page that would need to change the first time we vacuum a > full page with no dead tuples? I would have assumed the answer was > "no" (since if so I think it would follow that _all_ pages need > updated the first time they're vacuumed?). You probably know that hint bits are written by the first process to access the tuple after it was written. I think you're asking if the first *vacuum* requires additional writes beyond that. And I think vacuum wouldn't touch the page until it decides to freeze tuples. I do have a patch to display the number of hint bits written and pages frozen. https://www.postgresql.org/message-id/flat/20200126141328.GP13621%40telsasoft.com > But if that's the case, then this kind of opportunistic freezing wouldn't > help this kind of workload. Maybe there's something I'm misunderstanding > about how vacuum works though. I am reminding myself about vacuum with increasing frequency and usually still learn something new. -- Justin