Re: Postgres eats up memory when using cursors

Peter Eisentraut <peter_e@gmx.net>

From: Peter Eisentraut <peter_e@gmx.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Denis Perchine <dyp@perchine.com>, <pgsql-general@postgresql.org>
Date: 2001-03-01T18:12:16Z
Lists: pgsql-general
Tom Lane writes:

> Curiously, there does seem to be a leak in psql, or possibly libpq,
> when running this script.  It's per-query not per-tuple, so it's
> easier to see if you make the fetches shorter:
>
> fetch 100 from senders_c
> \g zzz
> fetch backward 100 from senders_c
> \g zzz
>
> Repeating these like mad, psql grows about 1Kb/sec on my machine.
> This occurs with current sources but NOT with 7.0.2 psql.  Peter,
> any thoughts about that?

Well, here's a memory leak:

Index: print.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/bin/psql/print.c,v
retrieving revision 1.16
diff -c -r1.16 print.c
*** print.c     2001/02/27 08:13:27     1.16
--- print.c     2001/03/01 17:30:00
***************
*** 1116,1121 ****
--- 1116,1122 ----
                free(footers[0]);
                free(footers);
        }
+       free(align);
  }


===snip

This leaks (columns + 1) per query, 4 bytes in your case.  But is has been
there in 7.0 as well.

I couldn't find anything suspicious in the CVS diffs of psql or libpq
since 7.0.

So let's think:  What if you use COPY?  \copy?  Plain SELECT?  What's the
leakage per query cycle (not per second)?  Is it related to the size of
the data?

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/