Re: Error: dsa_area could not attach to a segment that has been freed

From: Gaddam Sai Ram <gaddamsairam(dot)n(at)zohocorp(dot)com>
To: "Thomas Munro" <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Error: dsa_area could not attach to a segment that has been freed
Date: 2017-09-20 06:14:24
Message-ID: 15e9dec5358.f19835f310045.8997056759328389356@zohocorp.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you very much! That fixed my issue! :)
I was in an assumption that pinning the area will increase its lifetime but yeah after taking memory context into consideration its working fine!

Regards

G. Sai Ram

---- On Wed, 20 Sep 2017 11:16:19 +0530 Thomas Munro &lt;thomas(dot)munro(at)enterprisedb(dot)com&gt; wrote ----

On Fri, Sep 15, 2017 at 7:51 PM, Gaddam Sai Ram

&lt;gaddamsairam(dot)n(at)zohocorp(dot)com&gt; wrote:

&gt; As i'm pinning the dsa mapping after attach, it has to stay through out the

&gt; backend session. But not sure why its freed/corrupted.

&gt;

&gt; Kindly help me in fixing this issue. Attached the copy of my extension,

&gt; which will reproduce the same issue.

Your DSA area is pinned and the mapping is pinned, but there is one

more thing that goes away automatically unless you nail it to the

table: the backend-local dsa_area object which dsa_create() and

dsa_attach() return. That's allocated in the "current memory

context", so if you do it from your procedure simple_udf_func without

making special arrangements it gets automatically freed at end of

transaction. If you're going to cache it for the whole life of the

backend, you'd better make sure it's allocated in memory context that

lives long enough. Where you have dsa_create() and dsa_attach()

calls, try coding like this:

MemoryContext old_context;

old_context = MemoryContextSwitchTo(TopMemoryContext);

area = dsa_create(...);

MemoryContextSwitchTo(old_context);

old_context = MemoryContextSwitchTo(TopMemoryContext);

area = dsa_attach(...);

MemoryContextSwitchTo(old_context);

You'll need to #include "utils/memutils.h".

--

Thomas Munro

http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mithun Cy 2017-09-20 06:18:13 Re: SendRowDescriptionMessage() is slow for queries with a lot of columns
Previous Message Amit Khandekar 2017-09-20 06:02:36 Re: Parallel Append implementation