From: dean.a.rasheed@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #9371: pg_dump acquiring ROW EXCLUSIVE locks on tables
Date: Thu, 27 Feb 2014 11:54:14 +0000
Message-ID: <20140227115414.29525.45733@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 9371
Logged by: Dean Rasheed
Email address: dean.a.rasheed@gmail.com
PostgreSQL version: 8.4.20
Operating system: Linux
Description:
[Spotted in 8.4, but also tested in 9.4devel]
On one of our production systems we are having a problem that some client
processes are being blocked by pg_dump, and therefore having to wait a long
time before they can run. The clients in question are attempting to obtain
an explicit SHARE lock on a table to prevent concurrent data changes, and it
turns out that pg_dump is obtaining a ROW EXCLUSIVE lock on those tables for
the duration of the dump.
Further digging revealed that pg_dump obtains a ROW EXCLUSIVE lock on any
table mentioned in an INSERT, UPDATE or DELETE RULE. Wondering how that can
happen, I tried the following test case, describing a relation:
CREATE TABLE t (a int);
CREATE VIEW v AS SELECT * FROM t;
CREATE RULE r AS ON INSERT TO v DO INSTEAD INSERT INTO t VALUES(NEW.a);
BEGIN;
\d+ v
SELECT mode FROM pg_locks where relation = 't'::regclass;
COMMIT;
Result:
mode
------------------
AccessShareLock
RowExclusiveLock
(2 rows)
whereas I would expect at most an ACCESS SHARE lock.
The reason is that in ruleutils.c, pg_get_ruledef()/make_ruledef() and
get_query_def() are calling AcquireRewriteLocks() on the rule query, which
acquires a ROW EXCLUSIVE lock on its target table, even though the query is
not about to be run in this context. The calls to AcquireRewriteLocks() do
seem to be necessary to handle dropped columns, but perhaps
AcquireRewriteLocks() could be told that the query is not about to be run in
this case, and that it should only acquire ACCESS SHARE locks on the
tables.
Regards,
Dean
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: dean.a.rasheed@gmail.com
Subject: Re: BUG #9371: pg_dump acquiring ROW EXCLUSIVE locks on tables
In-Reply-To: <20140227115414.29525.45733@wrigleys.postgresql.org>
References: <20140227115414.29525.45733@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox