[postgis-users] Union as an aggregate

strk strk at keybit.net
Mon Sep 29 15:33:21 PDT 2003


Dave, I made no special 'unite' code, just sql create command:
CREATE AGGREGATE unite (
	sfunc = GeomUnion,
	basetype = geometry,
	stype = geometry
);

On pgsql-general somebody told me to upgrade to pgsql > 7.3.2
because there was a memory leak in plpgsql interpreter, but
that did not resolve the problem.

> Postgresql will automagically pfree() anything you palloc()
> at the end of the SQL statement.

When does an aggregate statement end ?
If it ends when finished with a group (group by)
or worst at the end of result set its worth pfree()'ing
passed attributes immediatly ... this should not influence
memory not being released at end of query (I have to
quit the monitor and start it again to have resources
released).

As for the malloced segments: when does the system 
force the release of segments allocated by shared libraries ?
Are them process based anyway (I mean: will memory allocated
by GEOS be released when postgres quit?).

--strk;

dblasby wrote:
> strk wrote:
> > I made my dumbass-mode aggregate (unite!).
> > It eats up all available memory, which remains allocated
> > also at the end of function run.
> > Does it sound as a postgresql bug ?
> > 
> > To reduce memory occupation it might be useful to release detoasted
> > values passed as arguments to geomunion with pfree, because
> > those allocations might remain 'till the end of the aggregate
> > run, but I'm not sure about palloced values life/aggregates.
> 
> I havent noticed postgresql chewing memory.  But, I must admit I dont 
> check that very carefully.  Postgresql will automagically pfree() 
> anything you palloc() at the end of the SQL statement.
> 
> Are you releasing your GEOS geometries?  You have to be careful because 
> they use malloc() instead of palloc().
> 
> Are you using the most up-to-date PostGIS and GEOS?
> 
> If so, send me the code to unite() and I'll take a quick look at it.
> 
> dave




More information about the postgis-users mailing list