Re: cursor interface to libpq - Mailing list pgsql-interfaces

From Thomas Lockhart
Subject Re: cursor interface to libpq
Date
Msg-id 39C84F0A.9E6C5947@alumni.caltech.edu
Whole thread Raw
In response to cursor interface to libpq  ("Kirby Bohling (TRSi)" <kbohling@oasis.novia.net>)
Responses Re: cursor interface to libpq
Re: cursor interface to libpq
List pgsql-interfaces
> I am trying to run a select statement, and I keep running out of
> memory.  I have noticed that libpq has the nice feature that I don't have
> to request each row one at a time.  After a little investigate, I found
> that libpq appears to get the entire result set at once.  Well, at least
> PQgetvalue() doesn't appear to do anything besides return a pointer to a
> string.  There is no lazy evaluation.  It doesn't just fetch the row I
> need, and flush old ones as memory permits.

Use a cursor at the query level to keep the result set in the backend.
But you will still (possibly) run out of memory, since the *backend*
must keep the result set in memory and/or on disk. Make sure you have
enough swap space, disk space, and main memory to handle the size of
database you have.

>         Is there any interface that I can link to a C/C++ program that
> will allow me row at a time access to the data?  Not being able to run
> select statements is going to be a fairly sizeable problem for me.

Look at cursors, but that doesn't eliminate the need for enough memory.

Expect to buy more memory, and make sure you have enough swap space.
Send more details on what you have currently and what your database
looks like and we can give you better feedback on your resource
requirements.
                     - Thomas


pgsql-interfaces by date:

Previous
From: Tom Samplonius
Date:
Subject: Re: PHP & Large Object
Next
From: Tom Lane
Date:
Subject: Re: cursor interface to libpq