Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZgwE1-0001NT-5n for pgsql-general@arkaria.postgresql.org; Tue, 29 Sep 2015 14:49:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZgwE0-00033b-OC for pgsql-general@arkaria.postgresql.org; Tue, 29 Sep 2015 14:49:48 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZgwBj-0006sG-Um for pgsql-general@postgresql.org; Tue, 29 Sep 2015 14:47:28 +0000 Received: from mail1.openerp.com ([46.105.124.125]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZgwBg-0002Ff-O1 for pgsql-general@postgresql.org; Tue, 29 Sep 2015 14:47:26 +0000 Received: by mail1.openerp.com (Postfix, from userid 10002) id 0C067BF530; Tue, 29 Sep 2015 16:47:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.openerp.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from [10.10.23.17] (host-109-89-171-142.dynamic.voo.be [109.89.171.142]) (Authenticated sender: odo@mail1.openerp.com) by mail1.openerp.com (Postfix) with ESMTPSA id A9DCABF41D for ; Tue, 29 Sep 2015 16:47:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=odoo.com; s=mail; t=1443538041; bh=8X8c9O+dunHILnv5/yR38O1zcFrJLlxqbs/WLY+VtCg=; h=From:Subject:To:Date:From; b=OmplBiYqROUPy2QM18PWvk61ifl23GGu5scVfs//wSAu1etwTDcnF7jMViDhXPVZ3 TEcSsTXLHulPGOBN7GeHvcQjm3Z+DFztngeKG/iopoJ6T2VYTp6YZ9Ld3YXrOfFelv lE5W6eZFE88rZGLdDDnsTa2aMtcs/kFbgOzN5ZUg= From: Olivier Dony Subject: Serialization errors despite KEY SHARE/NO KEY UPDATE To: pgsql-general@postgresql.org Message-ID: <560AA479.4080807@odoo.com> Date: Tue, 29 Sep 2015 16:47:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org Using 9.3.9 and 9.4.4 I'm experiencing serialization errors that I have trouble explaining based on the documentation. The concurrent transactions are framework-driven and all of them are running in REPEATABLE READ isolation level. The error can be reproduced as shown below. T1 fails when acquiring the second KEY SHARE lock for the same row, but does not fail if only one of the T1 UPDATEs is executed, either the first or the second one. Is there some hidden read/write dependency at play here? My understanding of the KEY SHARE/NO KEY UPDATE locks introduced in 9.3 was that they would avoid side-effects/blocking between transactions that are only linked via FK constraints, as long as the target PK was not touched. Isn't it the case here? If not, is there a reliable way to make T2 fail instead of T1 in such situations? I've tried adding an explicit "SELECT date FROM users WHERE id = 1 FOR UPDATE NOWAIT" at the beginning of T2 but that doesn't block at all. Thanks for the clarifications! -- Setup tables CREATE TABLE users ( id serial PRIMARY KEY, name varchar, date timestamp ); CREATE TABLE orders ( id serial PRIMARY KEY, name varchar, user_id int REFERENCES users (id) ); INSERT INTO users (id, name) VALUES (1, 'foo'); INSERT INTO orders (id, name) VALUES (1, 'order 1'); -- Run 2 concurrent transactions: T1 and T2 T1 T2 |-----------------------------|----------------------------------| BEGIN ISOLATION LEVEL REPEATABLE READ; UPDATE orders SET name = 'order of foo', user_id = 1 WHERE id = 1; BEGIN ISOLATION LEVEL REPEATABLE READ; UPDATE users SET date = now() WHERE id = 1; COMMIT; UPDATE orders SET name = 'order of foo (2)', user_id = 1 WHERE id = 1; T1 fails with: ERROR: could not serialize access due to concurrent update CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."users" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x" -- Olivier -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general