Re: 7.2 crash... - Mailing list pgsql-bugs

From Tom Lane
Subject Re: 7.2 crash...
Date
Msg-id 28474.1016770978@sss.pgh.pa.us
Whole thread Raw
In response to 7.2 crash...  ("Rod Taylor" <rbt@zort.ca>)
Responses Re: 7.2 crash...  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: 7.2 crash...  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-bugs
"Rod Taylor" <rbt@zort.ca> writes:
> 7.2 crashes with the below function:
> CREATE OR REPLACE FUNCTION runMaintenance()
> RETURNS BOOL AS '
>   VACUUM;
>   SELECT TRUE;
> ' LANGUAGE sql;

AFAICS there is no way that we can support VACUUM inside a function;
the forced transaction commits that VACUUM performs will recycle any
memory allocated by the function executor, leading to death and
destruction upon return from VACUUM.

Accordingly, what we really need is a way of preventing VACUUM from
executing in the above scenario.  The IsTransactionBlock() test it
already has isn't sufficient.

I have thought of something that probably would be sufficient:

    if (!MemoryContextContains(QueryContext, vacstmt))
        elog(ERROR, "VACUUM cannot be executed from a function");

This is truly, horribly ugly ... but it'd get the job done, because only
interactive queries will generate parsetrees in QueryContext.

Can someone think of a better way?

            regards, tom lane

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: 7.2 crash...
Next
From: Bruce Momjian
Date:
Subject: Re: 7.2 crash...