Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZjDBD-0001AO-AQ for pgsql-general@arkaria.postgresql.org; Mon, 05 Oct 2015 21:20:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZjDBC-0002Az-Ld for pgsql-general@arkaria.postgresql.org; Mon, 05 Oct 2015 21:20:18 +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 1ZjD8w-00083Y-Rg for pgsql-general@postgresql.org; Mon, 05 Oct 2015 21:17:59 +0000 Received: from nm8-vm1.bullet.mail.gq1.yahoo.com ([98.136.218.224]) by makus.postgresql.org with esmtps (TLS1.0:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZjD8t-0001x9-KI for pgsql-general@postgresql.org; Mon, 05 Oct 2015 21:17:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s2048; t=1444079873; bh=qeL6pCz9gKQkIq4VoP1cMr8UZHukZ7gK3vp3mYExe+Y=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject:From:Subject; b=ewDNt4R3u1sB0414NeYEFjD8Czb+F63h7iOqCHvsIA0JCdroGWuo5O5dYDyn8libfmkD00dUdhFtlZRRQzSP/XH7zns39Cab97x2jTVU8m8VP8pwTAYymwmSutx7JiMTQl64CsfdtrtXHs037MlBL8dVNfOiRxKF0obXjfp+4rwSdmPEuu2NJEVx/NkKMbLjgzbcBY2OH3X1kG32yxo4hO9t61iKjy4RWugispy87rfDXFxjjsWUR1+9yDKAg4JYrFJlOynPCE0Jo+gG6uoRsE2+c+wt/OZt2GyXhwOO8MavpZBaZ0Lgm3Ghpeay27SGSArT09rF0cNNyuEncyTaWA== Received: from [216.39.60.181] by nm8.bullet.mail.gq1.yahoo.com with NNFMP; 05 Oct 2015 21:17:53 -0000 Received: from [98.137.12.207] by tm17.bullet.mail.gq1.yahoo.com with NNFMP; 05 Oct 2015 21:17:53 -0000 Received: from [127.0.0.1] by omp1015.mail.gq1.yahoo.com with NNFMP; 05 Oct 2015 21:17:53 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 321773.8022.bm@omp1015.mail.gq1.yahoo.com X-YMail-OSG: 3D1rZc4VM1lVS2wVM7ePQVwxTjj8JF2HYGsJte.l4ZB9evSfUjRe35YBL1yjR8S VkBMTtml0vwOb8Zphie7akb5Pj1u9LVwY005aj2Mi0oVXjE9zyQxC9woX9fMsMAB2Rxbk7gS6gOU F6zRDS.PqOGcCwxmyrXRTHMaJYjNB.ESggAT19l6ZnQ6h5duanv0MwbKoxNS12KZoIAC5QdnKaSi Fq0UydymFzqHZx1huimr6wfAondpxocuIpBZVsf__39BDUgUnrO6FdY2EMf5PVKBBsxJU87i7K8c s7vWdIGuiupHfh19gmWOs2mjlI5LrM7JUTLq5ImUgo9JDwXyDd2Q0_3hbrSg1M2CGYyr1HNUvenA Ciux_i79C6zj0_Zk4Frf4sW7ayBDHA4Xzm7D2lwCIQsnI10g1d_6k.zsUl7Z7n.NfcJ1EeeuRPAn FUWOAlRJEds.cvc04lSvCGFxcHNUkRrWUGrd7Dn.DTQdinxbx8fTlZMnIU0.fStsh Received: by 98.137.12.251; Mon, 05 Oct 2015 21:17:52 +0000 Date: Mon, 5 Oct 2015 21:17:52 +0000 (UTC) From: Kevin Grittner Reply-To: Kevin Grittner To: Jim Nasby , Olivier Dony Cc: "pgsql-general@postgresql.org" Message-ID: <1354271993.744124.1444079872314.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <560ED745.3050009@BlueTreble.com> References: <560ED745.3050009@BlueTreble.com> Subject: Re: Serialization errors despite KEY SHARE/NO KEY UPDATE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Length: 3853 X-Pg-Spam-Score: -2.7 (--) 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 [Sorry for the delay in responding -- was on vacation.] Jim Nasby wrote: > On 10/2/15 11:44 AM, Olivier Dony wrote: >> On 10/02/2015 12:28 AM, Jim Nasby wrote: >>> On 9/29/15 9:47 AM, Olivier Dony wrote: >>>> -- 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 =3D 'order of foo', >>>> user_id =3D 1 >>>> WHERE id =3D 1; >>>> >>>> BEGIN ISOLATION LEVEL >>>> REPEATABLE READ; >>>> >>>> UPDATE users >>>> SET date =3D now() >>>> WHERE id =3D 1; >>>> >>>> COMMIT; >>>> >>>> UPDATE orders >>>> SET name =3D 'order of foo (2)', >>>> user_id =3D 1 >>>> WHERE id =3D 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.=3D) $1 FOR KEY SHARE OF x" >>> >>> This isn't a locking failure, it's a serialization failure. I'm not sure >>> why it's happening though... is there an index on date? >> >> I don't think so. I can reproduce the problem with the queries quoted >> above, and the only index that seems to be present is the PK > I'm not sure. Perhaps Kevin Grittner (author of serializable patch) can > shed some light. This has nothing to do with the serializable patch[1], but it is related to the new multixact code in 9.3. I thought I remembered that this was a regression from 9.2 behavior which was fixed in a patch after being reported, and sure enough tests of the tips of branches showed that prior to 9.3 T2 blocked until T1 committed, rather than generating a serialization failure, while on 9.5 and master there was no blocking or error. Using `git bisect` to see where this was fixed shows: commit 05315498012530d44cd89a209242a243374e274d Author: Alvaro Herrera Date: Tue Jul 29 15:41:06 2014 -0400 Avoid uselessly looking up old LOCK_ONLY multixacts Commit 0ac5ad5134f2 removed an optimization in multixact.c that skipped fetching members of MultiXactId that were older than our OldestVisibleMXactId value. The reason this was removed is that it is possible for multixacts that contain updates to be older than that value. However, if the caller is certain that the multi does not contain an update (because the infomask bits say so), it can pass this info down to GetMultiXactIdMembers, enabling it to use the old optimization. Pointed out by Andres Freund in 20131121200517.GM7240@alap2.anarazel.de I don't know whether, after being in 9.5 for over a year it could be considered for a back-patch to 9.3 and 9.4; I leave that to =C3=81lvaro and others who have been repairing the multixact problems to determine. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company [1] The serializable patch has no effect if there are not serializable transactions in use, and it doesn't generate errors "due to concurrent update" in any new situations. --=20 Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general