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.89) (envelope-from ) id 1gWWAf-0000KV-AJ for pgsql-general@arkaria.postgresql.org; Tue, 11 Dec 2018 00:45:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gWWAd-0002v8-G5 for pgsql-general@arkaria.postgresql.org; Tue, 11 Dec 2018 00:45:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gWWAd-0002v1-57 for pgsql-general@lists.postgresql.org; Tue, 11 Dec 2018 00:45:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gWWAZ-0008TE-L5 for pgsql-general@postgresql.org; Tue, 11 Dec 2018 00:45:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBB0j1GI000404; Mon, 10 Dec 2018 19:45:01 -0500 From: Tom Lane To: Thomas Carroll cc: "pgsql-general@postgresql.org" Subject: Re: Memory exhaustion due to temporary tables? In-reply-to: <1761071676.2037719.1544486470070@mail.yahoo.com> References: <2114009259.1866365.1544469996900.ref@mail.yahoo.com> <2114009259.1866365.1544469996900@mail.yahoo.com> <2584.1544474727@sss.pgh.pa.us> <1497611735.1978595.1544479049695@mail.yahoo.com> <7049.1544482214@sss.pgh.pa.us> <1761071676.2037719.1544486470070@mail.yahoo.com> Comments: In-reply-to Thomas Carroll message dated "Tue, 11 Dec 2018 00:01:10 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <402.1544489101.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 10 Dec 2018 19:45:01 -0500 Message-ID: <403.1544489101@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Carroll writes: > On Monday, December 10, 2018, 5:50:22 PM EST, Tom Lane wrote: = >> Also, as mentioned upthread, it'd be interesting to see if there's >> a memory context dump showing up in your server log. > There are many memory context dumps, and they are long (well over 100 li= nes apiece).=C2=A0 To me these are unfamiliar and hard to read, but I trie= d to pick one that referenced all the same tables used in the function.=C2= =A0 I put one such dump (188 lines) here: > https://drive.google.com/file/d/1QI4nffdZByIehb_-GULOagI_dKpKElg_/view Thanks. Here's the smoking gun: CacheMemoryContext: 221241400 total in 38 blocks; 152192 free (90 chunks= ); 221089208 used This looks like something is leaking memory directly in CacheMemoryContext (not in any of its child contexts). Can you confirm that all the memory context dumps in your logs are showing similarly very-large total space values for CacheMemoryContext? This doesn't seem to be related to temp table usage, at least not directly. (As a cross-check, I created and dropped 10000 temp tables in a session, and the process's VM footprint didn't budge.) My guess is that something else you are doing is tickling the leak. You said you'd been able to reproduce this problem outside production. Any chance you could boil that down to a sharable test case? I'd bet long odds that it's not related to your data particularly, but rather to your schema or something your function is doing, so you probably could reproduce it with some dummy data (and, perhaps, not even very much of that; repeating some DDL action many times is probably what is making the leak grow to something noticeable). If I had to guess at this point, I'd wonder if it's something to do with partitioned tables. That code is still relatively wet behind the ears, and memory leaks are the kind of bug I'd be expecting to still be shaking out of it now. But you might not be using partitioned tables at all. Anyway, anything you're doing with new-in-v10 features, particularly schema-related features, would be a good bet for the source of the problem. regards, tom lane