Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZS9pV-0005bp-HE for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Aug 2015 20:19:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZS9pV-0002np-2b for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Aug 2015 20:19:25 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZS9os-0001pN-8E for pgsql-bugs@postgresql.org; Wed, 19 Aug 2015 20:18:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZS9op-0007u8-TT for pgsql-bugs@postgresql.org; Wed, 19 Aug 2015 20:18:45 +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 t7JKIQXf018771; Wed, 19 Aug 2015 16:18:26 -0400 From: Tom Lane To: Haribabu Kommi cc: Heikki Linnakangas , Michael Paquier , "Behn, Edward (EBEHN)" , "pgsql-bugs@postgresql.org" Subject: Re: Memory leak with PL/Python trigger In-reply-to: References: <93F16B4BD93A7840AC75EB16E9494C7B211084DA@EXANPMB1.arinc.com> <55BB3C53.2030603@iki.fi> Comments: In-reply-to Haribabu Kommi message dated "Mon, 10 Aug 2015 11:41:39 +1000" Date: Wed, 19 Aug 2015 16:18:26 -0400 Message-ID: <18770.1440015506@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Haribabu Kommi writes: > Here I attached updated patch with a context allocation in > "PLy_procedure_create" function and the same context is reset > in every function call of "PLy_procedure_get" for all PLY types. This isn't really going in the direction I had in mind. I think what we want is to get rid of *all* of plpython's retail allocations in TopMemoryContext. All the long-lived data about a given procedure, starting with its PLyProcedure struct and certainly including all the associated PLyTypeInfo stuff, ought to be in a per-procedure context, similarly to the way plpgsql manages it. Then you can just delete that context if the procedure definition changes, and not need any retail cleanup. Also, you can't just reset the context being used as fn_mcxt without any regard for the possibility that functions have stored pointers into that space (probably in their fn_extra). Really you ought to redo fmgr_info() if you do that. That means that this approach is fundamentally giving up the ability to cache type lookup data across calls at all, which is surely not what we want. I would envision the PLyTypeInfo structs as usually living in the per-procedure context, and that's where fn_mcxt would point as well. There might be some cases where we have to have shorter-lived PLyTypeInfos, but the normal case ought to work like that. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs