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 1oJNS8-0004Vv-Nj for pgsql-general@arkaria.postgresql.org; Wed, 03 Aug 2022 23:07: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 1oJNR8-0006nc-Vv for pgsql-general@arkaria.postgresql.org; Wed, 03 Aug 2022 23:05:58 +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 1oJNR8-0006nR-LJ for pgsql-general@lists.postgresql.org; Wed, 03 Aug 2022 23:05:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJNR5-0001ni-PE for pgsql-general@lists.postgresql.org; Wed, 03 Aug 2022 23:05:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 273N5qTa3258037; Wed, 3 Aug 2022 19:05:52 -0400 From: Tom Lane To: =?UTF-8?B?QWxlxaEgWmVsZW7DvQ==?= cc: Tomas Vondra , Michael Paquier , "pgsql-generallists.postgresql.org" Subject: Re: PostgreSQL 14.4 ERROR: out of memory issues In-reply-to: References: <695843.1658154336@sss.pgh.pa.us> <787006.1658171039@sss.pgh.pa.us> Comments: In-reply-to =?UTF-8?B?QWxlxaEgWmVsZW7DvQ==?= message dated "Thu, 04 Aug 2022 00:31:29 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3258035.1659567952.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 03 Aug 2022 19:05:52 -0400 Message-ID: <3258036.1659567952@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =3D?UTF-8?B?QWxlxaEgWmVsZW7DvQ=3D=3D?=3D writes: > CREATE OR REPLACE FUNCTION tescase (_id_data_provider integer, _external= _id > bigint DEFAULT NULL::bigint, _external_complete_id character varying > DEFAULT NULL::character varying) > RETURNS TABLE(id_gm bigint, id_opp bigint, id_opp_state integer) > LANGUAGE sql > AS $function$ > SELECT ... simple join of two tables... > WHERE opd.id_data_provider =3D _id_data_provider > AND CASE WHEN _external_id IS NULL > THEN external_id IS NULL > ELSE external_id =3D _external_id > END > AND CASE WHEN _external_complete_id IS NULL > THEN _external_complete_id IS NULL > ELSE external_complete_id =3D _external_complete_id > END; > $function$ > ; > It is a kind of creative construct for me, but it works. The key here is > that if I replace at least one of the "CASEd" where conditions, it seems > not to suffer from the memory leak issue. > Finally, I've found, that even having the function as is and before the > test disabling JIT (SET jit =3D off;) and calling the function 100k time= s, > RssAnon memory for the given process is stable and only 3612 kB, while w= hen > JIT is enabled (the default setting on the server suffering from the mem= ory > leak, RssAnon memory for the given process growth in a linear manner ove= r > time (canceled when it reached 5GB). Ah. I bet this is another instance of the known memory leakage problems with JIT inlining [1]. Per Andres' comments in that thread, it seems hard to solve properly. For now all I can recommend is to disable that. regards, tom lane [1] https://www.postgresql.org/message-id/flat/20201001021609.GC8476%40tel= sasoft.com