Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvhjs-0000JP-HQ for pgsql-hackers@arkaria.postgresql.org; Sat, 23 Sep 2017 10:32:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dvhjs-0002Lt-4L for pgsql-hackers@arkaria.postgresql.org; Sat, 23 Sep 2017 10:32:48 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dvhiL-00080a-4m for pgsql-hackers@postgresql.org; Sat, 23 Sep 2017 10:31:13 +0000 Received: from smtprelay0081.b.hostedemail.com ([64.98.42.81] helo=smtprelay.b.hostedemail.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dvhiG-0007aD-QX for pgsql-hackers@postgresql.org; Sat, 23 Sep 2017 10:31:12 +0000 Received: from filter.hostedemail.com (10.5.19.248.rfc1918.com [10.5.19.248]) by smtprelay06.b.hostedemail.com (Postfix) with ESMTP id 0D1CA8D016; Sat, 23 Sep 2017 10:31:05 +0000 (UTC) X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,alvherre@alvh.no-ip.org,:::,RULES_HIT:41:355:379:599:967:973:988:989:1260:1277:1311:1312:1313:1314:1345:1359:1437:1515:1516:1518:1519:1534:1543:1593:1594:1595:1596:1711:1730:1747:1777:1792:2393:2525:2540:2560:2563:2682:2685:2689:2693:2828:2859:2915:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4605:5007:6119:6261:7875:7903:8660:8957:9025:9121:10004:10394:10400:10848:11026:11232:11658:11914:12043:12296:12438:12663:13148:13161:13229:13230:13439:13894:13895:14181:14721:14819:21067:21080:21324:21433:21627:30054:30069:30070,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: hand01_60cf193314914 X-Filterd-Recvd-Size: 3939 Received: from alvin.alvh.no-ip.org (pd95c76e8.dip0.t-ipconnect.de [217.92.118.232]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf02.b.hostedemail.com (Postfix) with ESMTPA; Sat, 23 Sep 2017 10:31:05 +0000 (UTC) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 72B9E1033; Sat, 23 Sep 2017 12:30:50 +0200 (CEST) Date: Sat, 23 Sep 2017 12:30:50 +0200 From: Alvaro Herrera To: Tom Lane Cc: pgsql-hackers@postgreSQL.org Subject: Re: Rethinking autovacuum.c memory handling Message-ID: <20170923103050.decvu4b3qqnjti67@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <13849.1506114543@sss.pgh.pa.us> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Tom Lane wrote: > I notice that autovacuum.c calls autovacuum_do_vac_analyze, and > thereby vacuum(), in TopTransactionContext. This doesn't seem > like a terribly great idea, because it doesn't correspond to what > happens during a manually-invoked vacuum. TopTransactionContext > will go away when vacuum() commits the outer transaction, whereas > in non-autovac usage, we call vacuum() in a PortalHeapMemory > context that is not a child of TopTransactionContext and is not > at risk of being reset multiple times during the vacuum(). This'd > be a hazard if autovacuum_do_vac_analyze or vacuum did any palloc's > before getting to the main loop. More generally, I'm not aware of > other cases where we invoke a function in a context that we know > that function will destroy as it executes. Oh, good catch. This must be a very old oversight -- I bet it goes all the way back to the introduction of autovacuum. I think if there were any actual bugs, we would have noticed by now. > I don't see any live bug associated with this in HEAD, but this behavior > requires a rather ugly (and memory-leaking) workaround in the proposed > patch to allow multiple vacuum target rels. Well, it's definitely broken, so I'd vote for fixing it even if we weren't considering that patch. > What I think we should do instead is invoke autovacuum_do_vac_analyze > in the PortalContext that do_autovacuum has created, which we already > have a mechanism to reset once per table processed in do_autovacuum. Sounds sensible. > The attached patch does that, and also modifies perform_work_item() > to use the same approach. Right now perform_work_item() has a > copied-and-pasted MemoryContextResetAndDeleteChildren(PortalContext) > call in its error recovery path, but that seems a bit out of place > given that perform_work_item() isn't using PortalContext otherwise. Oops :-( > PS: I was disappointed to find out that perform_work_item() isn't > exercised at all in the standard regression tests. Yeah ... It's fairly simple to create a test that will invoke it a few times, but one problem is that it depends on autovacuum's timing. If I add this in brin.sql -- Test BRIN work items CREATE TABLE brin_work_items (LIKE brintest) WITH (fillfactor = 10); CREATE INDEX brin_work_items_idx ON brin_work_items USING brin (textcol) WITH (autosummarize = on, pages_per_range=1); INSERT INTO brin_work_items SELECT * FROM brintest; the work item is only performed about 15 seconds after the complete regression tests are finished, which I fear would mean "never" in practice. One idea I just had is to somehow add it to src/test/modules/brin, and set up the postmaster in that test with autovacuum_naptime=1s. I'll go check how feasible that is. (By placing it there we could also verify that the index does indeed contain the index entries we expect, since it has pageinspect available.) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers