Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTJaC-0006f1-6J for pgsql-general@arkaria.postgresql.org; Mon, 05 Apr 2021 07:23:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lTJa9-00016g-Q9 for pgsql-general@arkaria.postgresql.org; Mon, 05 Apr 2021 07:23:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTJa9-00016X-IZ for pgsql-general@lists.postgresql.org; Mon, 05 Apr 2021 07:23:33 +0000 Received: from [2a01:4f9:3a:121a::2] (helo=mail.stephans-server.de) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTJa6-0001na-KU for pgsql-general@lists.postgresql.org; Mon, 05 Apr 2021 07:23:32 +0000 Received: from [192.168.178.22] ([::ffff:87.123.116.119]) (AUTH: PLAIN knauss, ) by mail.stephans-server.de with ESMTPSA id 00000000002A0A43.00000000606ABAEC.00093832; Mon, 05 Apr 2021 09:23:24 +0200 Subject: Re: Debugging leaking memory in Postgresql 13.2/Postgis 3.1 To: Tom Lane Cc: "pgsql-generallists.postgresql.org" References: <9f73e655-14b8-feaf-bd66-c0f506224b9e@stephans-server.de> <2919657.1617129981@sss.pgh.pa.us> <6ea52e56-b401-7716-f592-a8fdc98df667@stephans-server.de> <3269480.1617215050@sss.pgh.pa.us> From: Stephan Knauss Message-ID: <699cb370-17b8-3e72-02fe-1f96d494dfd7@stephans-server.de> Date: Mon, 5 Apr 2021 09:23:23 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <3269480.1617215050@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:4f9:3a:121a::2 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Tom, On 31.03.2021 20:24, Tom Lane wrote: > Based on nearby threads, it occurs to me to ask whether you have JIT > enabled, and if so whether turning it off helps. There seems to be > a known leak of the code fragments generated by that in some cases. That's it! I am quite surprised that a functionality, which is on by default does generate such a massive leak and goes sort of undetected. A single backend was leaking 250MB/hour, with my multiple connections it was 2GB. But exactly that happened. Doing a set jit=off immediately stopped the leak. You mentioned that this seems to be known. Do you have pointers to the relevant bug-tracker/thread? I would like to follow up on this. I have not measured the impact of jit, but in theory it could bring larger performance benefits. So having it enabled sounds like a good idea, once it stops leaking. I tried running Valgrind on postgres but I had not much success with it. processes seemed to terminate quite frequently. My last use of Valgrind is a while ago and my use-case back then was probably much simpler. Is it known which queries are leading to a leak? I still have the recording of mine, including explain. Would it help to narrow it further down to single queries which leak? Or is the JIT re-creating optimized code for each slightly modified one without freeing the old ones? So re-running the same query would not leak? https://downloads.osm-tools.org/postgresql-2021-04-03_183913.csv.gz Stephan