Retrieve memory size allocated by libpq

Lars Kanis <lars@greiz-reinsdorf.de>

From: Lars Kanis <lars@greiz-reinsdorf.de>
To: pgsql-hackers@postgresql.org
Cc: Sam Saffron <sam.saffron@gmail.com>
Date: 2018-06-23T19:58:43Z
Lists: pgsql-hackers

Attachments

Hello,

I would like to be able to retrieve the size of memory internally
allocated by libpq for a result. The reason is that we have a Ruby
wrapper that exposes libpq in Ruby. The problem is that Ruby's GC
doesn't know how much memory has been allocated by libpq, so no pressure
is applied to the GC when it should be. With this function we could
instruct the GC about the memory usage associated to each result object.

This issue has already been discussed in the following thread, with the
request to use custom malloc/realloc/free functions:

https://www.postgresql.org/message-id/flat/20170828172834.GA71455%40TC.local#20170828172834.GA71455@TC.local

Retrieving the allocated memory size is another approach to solve the
same base issue. However since the relation between memory consumption
and the particular result object is maintained, it can additionally be
used to provide diagnostic information to each object.

What do you think about adding such a function?

--
Kind Regards,
Lars

Commits

  1. Add PQresultMemorySize function to report allocated size of a PGresult.