pgsql: Avoid getting more than AccessShareLock when deparsing a query. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Avoid getting more than AccessShareLock when deparsing a query.
Date
Msg-id E1WLihc-0007BV-RU@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Avoid getting more than AccessShareLock when deparsing a query.

In make_ruledef and get_query_def, we have long used AcquireRewriteLocks
to ensure that the querytree we are about to deparse is up-to-date and
the schemas of the underlying relations aren't changing.  Howwever, that
function thinks the query is about to be executed, so it acquires locks
that are stronger than necessary for the purpose of deparsing.  Thus for
example, if pg_dump asks to deparse a rule that includes "INSERT INTO t",
we'd acquire RowExclusiveLock on t.  That results in interference with
concurrent transactions that might for example ask for ShareLock on t.
Since pg_dump is documented as being purely read-only, this is unexpected.
(Worse, it used to actually be read-only; this behavior dates back only
to 8.1, cf commit ba4200246.)

Fix this by adding a parameter to AcquireRewriteLocks to tell it whether
we want the "real" execution locks or only AccessShareLock.

Report, diagnosis, and patch by Dean Rasheed.  Back-patch to all supported
branches.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/f557826f8db1015c55473b8a3343faa96b480aed

Modified Files
--------------
src/backend/commands/matview.c       |    2 +-
src/backend/rewrite/rewriteHandler.c |   68 ++++++++++++++++++++++++----------
src/backend/utils/adt/ruleutils.c    |    7 +++-
src/include/rewrite/rewriteHandler.h |    4 +-
4 files changed, 57 insertions(+), 24 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Avoid getting more than AccessShareLock when deparsing a query.
Next
From: Tom Lane
Date:
Subject: pgsql: Avoid getting more than AccessShareLock when deparsing a query.