Re: Postgres eats up memory when using cursors

From: Denis Perchine <dyp(at)perchine(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Postgres eats up memory when using cursors
Date: 2001-03-01 17:25:38
Message-ID: 01030123253806.00608@dyp.perchine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Looks pretty simple to me too; I was expecting that you were doing
> expression evaluations or some such. I cannot reproduce any backend
> leakage in this query, either in 7.0.* or current sources. I did
>
> create table senders (email text, first_name text, last_name text);
> \copy senders from 'todo' -- some junk data
> create index sendersi on senders(email);
> insert into senders select * from senders; -- repeat a few times
>
> begin;
> explain
> declare senders_c cursor for select email, first_name, last_name
> from senders order by email;
> NOTICE: QUERY PLAN:
>
> Index Scan using sendersi on senders (cost=0.00..102.78 rows=2161
> width=36)
>
> end;
>
> then made a script file
>
> begin;
> declare senders_c cursor for select email, first_name, last_name
> from senders order by email;
>
> fetch 10000 from senders_c
> \g zzz
> fetch backward 10000 from senders_c
> \g zzz
> fetch 10000 from senders_c
> \g zzz
> fetch backward 10000 from senders_c
> \g zzz
> fetch 10000 from senders_c
> \g zzz
> ... repeat a few thousand times ...
>
> end;
>
> Backend memory usage is absolutely rock steady.
>
> 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?

Actually you should also consider that there is really intensive inserts
happend at the same time. Cursor is closed in 3-4 days only...

--
Sincerely Yours,
Denis Perchine

----------------------------------
E-Mail: dyp(at)perchine(dot)com
HomePage: http://www.perchine.com/dyp/
FidoNet: 2:5000/120.5
----------------------------------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Wood 2001-03-01 17:27:45 Re: JOIN of a table with many detail tables
Previous Message Brian Kurt Fujikawa 2001-03-01 17:23:00 insert into table from C/C++ application