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 1pyYzS-00030j-5W for pgsql-hackers@arkaria.postgresql.org; Mon, 15 May 2023 14:15:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pyYzR-0002Bi-0X for pgsql-hackers@arkaria.postgresql.org; Mon, 15 May 2023 14:15:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pyYzQ-0002BZ-Mm for pgsql-hackers@lists.postgresql.org; Mon, 15 May 2023 14:15:52 +0000 Received: from mail1.dalibo.net ([51.159.93.128] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pyYzO-002tCb-AG for pgsql-hackers@lists.postgresql.org; Mon, 15 May 2023 14:15:52 +0000 Received: from karst (larco.ioguix.net [78.202.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id E8D431F89D; Mon, 15 May 2023 16:15:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1684160128; bh=ZS3qCAcaMA/hRnqBcWHpqvbv/cevAglyyGeRSnuYEkY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JF7RoyDoPnUrC4UBg8BGYdHzAbXd/BazIDXqQkbbnMG5ftU1yz77M3WK9+gpvxi67 0zL0lOr9QAwjriI68MqXwqUhPj0IwQ+9TBZ2V8LkiAw1JJXX7V+lRS7Raa12IqIRDh pK2VI3eSuVnrg+6HLNMKaw4rUWAyuzuz2ivC83OM= Date: Mon, 15 May 2023 16:15:26 +0200 From: Jehan-Guillaume de Rorthais To: Tomas Vondra Cc: pgsql-hackers@lists.postgresql.org, Konstantin Knizhnik , Thomas Munro Subject: Re: Memory leak from ExecutorState context? Message-ID: <20230515161526.5d05708d@karst> In-Reply-To: References: <20230327231323.08277083@karst> <20230328151745.0f6061f8@karst> <20230331140611.3695d30d@karst> <20230408020119.32a0841b@karst> <20230504193006.1b5b9622@karst> <20230508155648.lzddwywo6emote2b@liskov> <20230510142419.6185a492@karst> <20230512213606.isxoy2s57majc4ji@liskov> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 14 May 2023 00:10:00 +0200 Tomas Vondra wrote: > On 5/12/23 23:36, Melanie Plageman wrote: > > Thanks for continuing to work on this. > >=20 > > Are you planning to modify what is displayed for memory usage in > > EXPLAIN ANALYZE? Yes, I already start to work on this. Tracking spilling memory in spaceUsed/spacePeak change the current behavior of the serialized HJ becaus= e it will increase the number of batch much faster, so this is a no go for v16. I'll try to accumulate the total allocated (used+not used) spill context me= mory in instrumentation. This is gross, but it avoids to track the spilling memo= ry in its own structure entry. > We could do that, but we can do that separately - it's a separate and > independent improvement, I think. +1 > Also, do you have a proposal how to change the explain output? In > principle we already have the number of batches, so people can calculate > the "peak" amount of memory (assuming they realize what it means). We could add the batch memory consumption with the number of batches. Eg.: =C2=A0=C2=A0Buckets: 4096 (originally 4096)=C2=A0=20 Batches: 32768 (originally 8192) using 256MB =C2=A0=C2=A0Memory Usage: 192kB > I think the main problem with adding this info to EXPLAIN is that I'm > not sure it's very useful in practice. I've only really heard about this > memory explosion issue when the query dies with OOM or takes forever, > but EXPLAIN ANALYZE requires the query to complete. It could be useful to help admins tuning their queries realize that the cur= rent number of batches is consuming much more memory than the join itself. This could help them fix the issue before OOM happen. Regards,