Skip site navigation (1) Skip section navigation (2)

Memory leak in FDW

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Memory leak in FDW
Date: 2011-04-26 18:06:51
Message-ID: 4DB709BB.1070504@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Foreign data wrapper's IterateForeignScan() function is supposed to be 
called in a short-lived memory context, but the memory context is 
actually not reset during query execution. That's a pretty bad memory 
leak. I've been testing this with file_fdw and a large file, and "SELECT 
COUNT(*) FROM foreign_table"

Interestingly, if you add any WHERE clause to it, the memory context is 
reset in ExecScan and the leak goes away. This is only a problem with 
the fastpath in ExecScan for the case of no quals and no projections.

The trivial fix is to reset the per-tuple memory context between 
iterations. I tried to look around for other executor nodes that might 
have the same problem. I didn't see any obvious leaks, although index 
scan node seems to call AM's getnext without resetting the memory 
context in between. That's a pretty well-tested codepath, however, and 
there hasn't been any complains of leaks with index scans, so there must 
be something that mitigates it.

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

Attachment: plug-foreign-scan-memory-leak-1.patch
Description: text/x-diff (733 bytes)

Responses

pgsql-hackers by date

Next:From: Alvaro HerreraDate: 2011-04-26 18:15:46
Subject: Re: Memory leak in FDW
Previous:From: Bruce MomjianDate: 2011-04-26 17:41:27
Subject: Re: Prefered Types

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group