Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKt6G-0002CH-JU for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Dec 2017 21:44:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eKt6G-0001Zw-3o for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Dec 2017 21:44:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eKt31-0006Jc-3q for pgsql-hackers@lists.postgresql.org; Fri, 01 Dec 2017 21:40:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eKt2x-0000XP-JB for pgsql-hackers@postgresql.org; Fri, 01 Dec 2017 21:40:37 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vB1LeP6o017772; Fri, 1 Dec 2017 16:40:25 -0500 From: Tom Lane To: Andres Freund cc: Robert Haas , Michael Paquier , Kyotaro HORIGUCHI , David Steele , Jim Nasby , Craig Ringer , PostgreSQL mailing lists Subject: Re: Protect syscache from bloating with negative cache entries In-reply-to: <20171201213113.z4gbol66ipvg5b4o@alap3.anarazel.de> References: <3b7b7f90-db46-8c37-c4f7-443330c3ae33@pgmasters.net> <20170317.142313.232290068.horiguchi.kyotaro@lab.ntt.co.jp> <20171031.184622.92520047.horiguchi.kyotaro@lab.ntt.co.jp> <84820.1512015443@sss.pgh.pa.us> <85587.1512101829@sss.pgh.pa.us> <20171201213113.z4gbol66ipvg5b4o@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Fri, 01 Dec 2017 13:31:13 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3543.1512164423.1@sss.pgh.pa.us> Date: Fri, 01 Dec 2017 16:40:23 -0500 Message-ID: <3544.1512164423@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > On 2017-12-01 16:20:44 -0500, Robert Haas wrote: >> Well, yeah, that would be insane. But I think even something very >> rough could work well enough. I think our goal should be to eliminate >> cache entries that are have gone unused for many *minutes*, and >> there's no urgency about getting it to any sort of exact value. For >> non-idle backends, using the most recent statement start time as a >> proxy would probably be plenty good enough. Idle backends might need >> a bit more thought. > Our timer framework is flexible enough that we can install a > once-a-minute timer without much overhead. That timer could increment a > 'cache generation' integer. Upon cache access we write the current > generation into relcache / syscache (and potentially also plancache?) > entries. Not entirely free, but cheap enough. In those once-a-minute > passes entries that haven't been touched in X cycles get pruned. I have no faith in either of these proposals, because they both assume that the problem only arises over the course of many minutes. In the recent complaint about pg_dump causing relcache bloat, it probably does not take nearly that long for the bloat to occur. Maybe you could make it work on the basis of number of cache accesses, or some other normalized-to-workload-not-wall-clock time reference. regards, tom lane