MemoryContextSwitchTo (Re: [GENERAL] Autovacuum daemon terminated by signal 11) - Mailing list pgsql-hackers

From Simon Riggs
Subject MemoryContextSwitchTo (Re: [GENERAL] Autovacuum daemon terminated by signal 11)
Date
Msg-id 1232182478.31669.182.camel@ebony.2ndQuadrant
Whole thread Raw
Responses Re: MemoryContextSwitchTo (Re: [GENERAL] Autovacuum daemon terminated by signal 11)
List pgsql-hackers
On Fri, 2009-01-16 at 18:43 -0500, Tom Lane wrote:

> What is happening is that autovacuum_do_vac_analyze contains
> 
>         old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
>         ...
>         vacuum(vacstmt, relids);
>         ...
>         MemoryContextSwitchTo(old_cxt);
> 
> and at the time it is called by process_whole_db, CurrentMemoryContext
> points at TopTransactionContext.  Which gets destroyed because
> vacuum()
> internally finishes that transaction and starts a new one.  When we
> come out of vacuum(), CurrentMemoryContext again points at
> TopTransactionContext, but *its not the same one*.  The closing
> MemoryContextSwitchTo is installing a stale pointer, which then
> remains active into CommitTransaction.  It's a wonder this code ever
> works.

Can we add something to memory contexts to make this fail every time?

Seems like we should be able to detect this class of error. If we can't
it seems likely that a number of similar cases exist with other
contexts.

-- Simon Riggs           www.2ndQuadrant.comPostgreSQL Training, Services and Support



pgsql-hackers by date:

Previous
From: KaiGai Kohei
Date:
Subject: Status Report on SE-PostgreSQL
Next
From: Alan Li
Date:
Subject: Fixes for compiler warnings