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 1lSlKO-0007ri-PL for pgsql-general@arkaria.postgresql.org; Sat, 03 Apr 2021 18:49:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lSlKN-0003ag-Mn for pgsql-general@arkaria.postgresql.org; Sat, 03 Apr 2021 18:48:59 +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 1lSlJM-00007O-QX for pgsql-general@lists.postgresql.org; Sat, 03 Apr 2021 18:47:56 +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 1lSlJJ-0002Gj-Vt for pgsql-general@lists.postgresql.org; Sat, 03 Apr 2021 18:47:55 +0000 Received: from [192.168.178.22] (i59F77309.versanet.de [::ffff:89.247.115.9]) (AUTH: PLAIN knauss, ) by mail.stephans-server.de with ESMTPSA id 00000000002A0C7C.000000006068B852.003EE6EA; Sat, 03 Apr 2021 20:47:46 +0200 Subject: Re: Debugging leaking memory in Postgresql 13.2/Postgis 3.1 To: Paul Ramsey , 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> <32593FA7-5D1C-4AEF-8584-C8F630E7AE8A@cleverelephant.ca> From: Stephan Knauss Message-ID: <9e64a21a-8b08-6d73-8d15-680b04dacafa@stephans-server.de> Date: Sat, 3 Apr 2021 20:47:45 +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: <32593FA7-5D1C-4AEF-8584-C8F630E7AE8A@cleverelephant.ca> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable 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 On 31.03.2021 20:27, Paul Ramsey wrote: > On Mar 31, 2021, at 11:24 AM, Tom Lane wrote: >> If that's not it, then the leak must be accumulating through plain >> old malloc calls. There's not much of that in the core backend >> (although if you use ispell text search dictionaries, maybe [1] is >> relevant), so my suspicions would next fall on any extensions you >> might be using. > Would be interested in the queries being run. We have a reproduceable l= eak in <-> geography operator that we have been unable to track down. > I tried to get any idea where the memory is by feeding my core file into = chap. I ended up not knowing how to proceed further. I found a=20 std::vector which was roughly 70 MB in size and a lot of allocations=20 chap could not identify where they belonged to: chap> summarize used Unrecognized allocations have 23098683 instances taking=20 0xe6973688(3,868,669,576) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x68 have 8214926 instance= s taking=20 0x32ec61b0(854,352,304) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x28 have 4890673 instance= s taking=20 0xba907a8(195,626,920) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x38 have 3255995 instance= s taking=20 0xade38e8(182,335,720) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x48 have 2096221 instance= s taking=20 0x8fefa28(150,927,912) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x78 have 1792042 instance= s taking=20 0xcd153b0(215,045,040) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x88 have 1393038 instance= s taking=20 0xb4ad370(189,453,168) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x58 have 657193 instances=20 taking=20 0x3727618(57,832,984) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0xa8 have 360742 instances=20 taking=20 0x39cc0f0(60,604,656) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x18 have 270834 instances=20 taking=20 0x632eb0(6,500,016) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x98 have 60372 instances = taking=20 0x8c05e0(9,176,544) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0xb8 have 37559 instances = taking=20 0x697388(6,910,856) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0xd8 have 19033 instances = taking=20 0x3ebb18(4,111,128) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x128 have 19010 instances=20 taking=20 0x55dc50(5,626,960) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0xe8 have 9526 instances t= aking=20 0x21b8f0(2,210,032) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x118 have 9513 instances = taking=20 0x28a4d8(2,663,640) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x1f8 have 9499 instances = taking=20 0x490d28(4,787,496) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x408 have 292 instances t= aking=20 0x49920(301,344) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x2008 have 194 instances = taking=20 0x184610(1,590,800) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x1008 have 155 instances = taking=20 0x9b4d8(636,120) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x4008 have 137 instances = taking=20 0x224448(2,245,704) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x8008 have 133 instances = taking=20 0x428428(4,359,208) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x10008 have 131 instances=20 taking=20 0x830418(8,586,264) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x40008 have 131 instances=20 taking=20 0x20c0418(34,341,912) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x100008 have 130 instance= s taking=20 0x8200410(136,315,920) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x20008 have 129 instances=20 taking=20 0x1020408(16,909,320) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x80008 have 129 instances=20 taking=20 0x4080408(67,634,184) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x200008 have 129 instance= s taking=20 0x10200408(270,533,640) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x400008 have 128 instance= s taking=20 0x20000400(536,871,936) bytes. =C2=A0=C2=A0 Unrecognized allocations of size 0x418 have 53 instances ta= king=20 0xd8f8(55,544) bytes. [...] Pattern %VectorBody has 57401 instances taking 0x42eaaf0(70,167,280) byte= s. [...] Pattern %MapOrSetNode has 51362 instances taking 0x3f2f40(4,140,864) byte= s. let me know if it would be interesting for you to have this (huge) core=20 file with memory dump available somewhere. I have executed a few minutes of queries on a single backend setup. The=20 RssAnon was growing during this time by about 10 MB in size. Full query logs are here:=20 https://downloads.osm-tools.org/postgresql-2021-04-03_183913.csv.gz I have the following extensions installed. hstore is heavily used and a=20 little bit postgis. gis=3D# SELECT extname FROM pg_extension; =C2=A0 extname ----------- =C2=A0plpgsql =C2=A0adminpack =C2=A0postgis =C2=A0hstore (4 rows) as per other suggestions I enabled auto_explain as well. I hope you can get a hint what is allocating the memory. I could offer=20 to share some docker images to reproduce, but It would require a few=20 commands to set it up and a few hundred megabytes of download. Stephan