Re: Memory leak in RelationBuildRowSecurity - Mailing list pgsql-bugs

From Konstantin Knizhnik
Subject Re: Memory leak in RelationBuildRowSecurity
Date
Msg-id 3f670fa6-5e81-fbd9-b880-eaa275f15e1c@postgrespro.ru
Whole thread Raw
In response to Re: Memory leak in RelationBuildRowSecurity  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Memory leak in RelationBuildRowSecurity  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs

On 25.09.2020 16:48, Tom Lane wrote:
> Konstantin Knizhnik <k.knizhnik@postgrespro.ru> writes:
>> There is memory leak in RelationBuildRowSecurity function - it converts
>> node to expression tree in current memory context:
> Hm ... this smells a whole lot like the issue we fixed recently for
> partition expressions, namely: what the devil are we doing reloading
> these expressions during RelationClearRelation?  We should delay
> populating that cache until the value is requested.

Sorry, this stack trace was obtained at 9.6 version of Postgres which 
the customer is using.
So may be the problem with cache invalidation is already fixed.
But the memory leak in RelationBuildRowSecurity is still present.
May be it is not so critical if RelationBuildRowSecurity will not be 
called many times in the same memory context.
But at least calling pfree for a tree is very strange idea: we should 
not do it all or allocate tree in separate memory context.

By the way - it is illustration how "SQL function data" is growing after 
each invocation of RelationBuildRowSecurity:

SQL function data: 57344 total in 3 blocks; 53112 free (278 chunks); 
4232 used
SQL function data: 289213248 total in 3137 blocks; 3281544 free (217 
chunks); 285931704 used
SQL function data: 578434688 total in 6265 blocks; 6581320 free (234 
chunks); 571853368 used
SQL function data: 1148488960 total in 12520 blocks; 4793680 free (17 
chunks); 1143695280 used
SQL function data: 2288597504 total in 25030 blocks; 1222064 free (221 
chunks); 2287375440 used



pgsql-bugs by date:

Previous
From: Max Vikharev
Date:
Subject: Re: BUG #16620: Autovacuum does not process certain databases after migration from postgresql 10
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #16636: Upper case issue in JSONB type