matviews do not lock relations during refresh - Mailing list pgsql-hackers

From Andres Freund
Subject matviews do not lock relations during refresh
Date
Msg-id 20131022232822.GB823737@alap2.anarazel.de
Whole thread Raw
List pgsql-hackers
Hi,

In an postgres build that has added instrumentation to detect cases
where indexes are index_open()ed without any locks on the underlying
relation, the matview code started to cry during the regression tests.

The problem seems to be that refresh_matview_datafill() uses
QueryRewrite() without previously using AcquireRewriteLocks() but as
QueryRewrite states:
 * ...
 * NOTE: the parsetree must either have come straight from the parser,
 * or have been scanned by AcquireRewriteLocks to acquire suitable locks.
 */

I think the missed locks could lead to postgres crashing under
concurrent DDL.

I've attached a quick patch that fixes the issue for me in HEAD, but I
am not 100% sure I understand the details of refresh_matview_datafill().

This probably needs to go into 9.3 in an adapted form.

Greetings,

Andres Freund

--
 Andres Freund                       http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Attachment

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: tracking commit timestamps
Next
From: Noah Misch
Date:
Subject: Re: Why the asprintf patch is still breaking the buildfarm