matviews do not lock relations during refresh

Started by Andres Freundover 12 years ago1 messageshackers
Jump to latest
#1Andres Freund
andres@anarazel.de

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

Attachments:

0001-Acquire-appropriate-locks-when-rewriting-during-REFR.patchtext/x-patch; charset=us-asciiDownload+9-3