Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WIzYR-0000jy-VB for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Feb 2014 11:55:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WIzYR-0004VE-By for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Feb 2014 11:55:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WIzYP-0004Tj-Nt for pgsql-bugs@postgresql.org; Thu, 27 Feb 2014 11:55:05 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WIzYN-00044l-6p for pgsql-bugs@postgresql.org; Thu, 27 Feb 2014 11:55:05 +0000 MIME-Version: 1.0 Subject: BUG #9371: pg_dump acquiring ROW EXCLUSIVE locks on tables To: pgsql-bugs@postgresql.org From: dean.a.rasheed@gmail.com Date: Thu, 27 Feb 2014 11:54:14 +0000 Message-ID: <20140227115414.29525.45733@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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