When is the MessageContext released?

Started by Andy Fanalmost 7 years ago3 messages
#1Andy Fan
zhihui.fan1213@gmail.com

Hi :
I run a query like "select * from t" and set the break like this:

break exec_simple_query
break MemoryContextDelete
commands
p context->name
c
end

I can see most of the MemoryContext is relased, but never MessageContext,
when will it be released?

/*
* Create the memory context we will use in the main loop.
*
* MessageContext is reset once per iteration of the main loop, ie, upon
* completion of processing of each command message from the client.
*/

I'm hacking the code with the latest commit.
https://github.com/postgres/postgres/commit/414a9d3cf34c7aff1c63533df4c40ebb63bd0840

Thanks!

#2Andres Freund
andres@anarazel.de
In reply to: Andy Fan (#1)
Re: When is the MessageContext released?

On 2019-02-27 14:08:47 +0800, Andy Fan wrote:

Hi :
I run a query like "select * from t" and set the break like this:

break exec_simple_query
break MemoryContextDelete
commands
p context->name
c
end

I can see most of the MemoryContext is relased, but never MessageContext,
when will it be released?

It's released above exec_simple_query, as it actually contains the data
that lead us to call exec_simple_query(). See the main for loop in
PostgresMain():

/*
* Release storage left over from prior query cycle, and create a new
* query input buffer in the cleared MessageContext.
*/
MemoryContextSwitchTo(MessageContext);
MemoryContextResetAndDeleteChildren(MessageContext);

Greetings,

Andres Freund

#3Andy Fan
zhihui.fan1213@gmail.com
In reply to: Andres Freund (#2)
Re: When is the MessageContext released?

Thanks you Andres for your time! this context is free with AllocSetReset
rather than AllocSetDelete, that makes my breakpoint doesn't catch it.

On Wed, Feb 27, 2019 at 2:15 PM Andres Freund <andres@anarazel.de> wrote:

Show quoted text

On 2019-02-27 14:08:47 +0800, Andy Fan wrote:

Hi :
I run a query like "select * from t" and set the break like this:

break exec_simple_query
break MemoryContextDelete
commands
p context->name
c
end

I can see most of the MemoryContext is relased, but never MessageContext,
when will it be released?

It's released above exec_simple_query, as it actually contains the data
that lead us to call exec_simple_query(). See the main for loop in
PostgresMain():

/*
* Release storage left over from prior query cycle, and
create a new
* query input buffer in the cleared MessageContext.
*/
MemoryContextSwitchTo(MessageContext);
MemoryContextResetAndDeleteChildren(MessageContext);

Greetings,

Andres Freund