Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zi5lv-0005v3-VE for pgsql-general@arkaria.postgresql.org; Fri, 02 Oct 2015 19:13:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zi5lv-0002Cw-Bp for pgsql-general@arkaria.postgresql.org; Fri, 02 Oct 2015 19:13:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Zi5lu-0002CV-EE for pgsql-general@postgresql.org; Fri, 02 Oct 2015 19:13:34 +0000 Received: from mail-by2on0100.outbound.protection.outlook.com ([207.46.100.100] helo=na01-by2-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Zi5lp-0005xj-WB for pgsql-general@postgresql.org; Fri, 02 Oct 2015 19:13:33 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jim.Nasby@bluetreble.com; Received: from decina.local (70.113.16.71) by BY2PR11MB0679.namprd11.prod.outlook.com (10.163.111.21) with Microsoft SMTP Server (TLS) id 15.1.280.20; Fri, 2 Oct 2015 19:13:24 +0000 Subject: Re: Serialization errors despite KEY SHARE/NO KEY UPDATE To: Olivier Dony References: <560AA479.4080807@odoo.com> <560DB385.2080904@BlueTreble.com> <560EB487.7010400@odoo.com> CC: , Kevin Grittner From: Jim Nasby Message-ID: <560ED745.3050009@BlueTreble.com> Date: Fri, 2 Oct 2015 14:13:09 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <560EB487.7010400@odoo.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [70.113.16.71] X-ClientProxiedBy: BY2PR02CA0056.namprd02.prod.outlook.com (10.141.216.46) To BY2PR11MB0679.namprd11.prod.outlook.com (25.163.111.21) X-Microsoft-Exchange-Diagnostics: 1; BY2PR11MB0679; 2:0jAwksWDBkRzmolCGrTUUUKJAp1AtYe9aQ0pvEaasQplCPQVu4hcUN+8VxxeY/jxLFVUkac/v4Z9rU1NPwio9cOBt/vwa86KSU4zzVUTtit9aEUwdVQ+WelshvSN16XN2PJm6V4oNXdKd13+Zg8P1awFoz7T5FQr3AeaF5w8pa0=; 3:lkXIl7LAMGinGvSID5ybNhxxuNbuOBwy87SAsrMWLIdzo+3FWTg7J237w7HPmj3CH5dpaZoDRNCiOIdrtINueJgtTGmoH8YPegZWVKrDuEF5W+edk3KzGFz+iCJGPB5o43M/PTrVH5CGuMIUScaYSQ==; 25:148V3ImTB9G1dcnBgjADLWNNmh0z/RajTqO74/Ype6wKSNvCxZFsQjmHQj6J/qowJ4npQgcKO1Qwz1ApYuQ06atsPk4Yn5EGsqwiRrp4Vm+xrJVpjp9MpDHuaMR55G15cXmbWOFY8hTAVhBxDg5XScCTIteSZgb0k/PtKiQXU9409X73EG619IEW4qYe2/KWKql63FV1oUnHI1iqWFiCu7rUiTJQ687N2yVk4KDtvtywQwBn6PSB69EJf6V2GMis9BfI+Pk46EyvDx+BD0FrZg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR11MB0679; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001); SRVR:BY2PR11MB0679; BCL:0; PCL:0; RULEID:; SRVR:BY2PR11MB0679; X-Microsoft-Exchange-Diagnostics: 1; BY2PR11MB0679; 4:W0+HgK3CY7ne84jCLyu0GOzXaekjPudM2AWdy0C7IOCSa7NRVnm1tbL5kODRXmQ1y6dZgCHvJVU2hvDVXN7rAyXJdjNtGGJwo47T7SA2O2LjP5F8S5qK8BpJNJkQ84OuGY2bYBUdUdab6jRqKqWfkcR2In+0HH2uPHlQXY9BJ9i6MVyZAlS/WSz80VclgnWeefG+BnKwoAKo3DLTd24nG+hZ0fQ2vse46thvucXA2Nje2LNvnIL4k0b7EUmI5ANnyenSN1zi8reF77AWB3+nCeBmZ2o4KUX+5DdBg9qCSdgz7fn8sUf0u1QIxxsIddFrb2NlCrIPbLvib12b/jC76v6ke0fbtSF43taC1pJm4i0= X-Forefront-PRVS: 0717E25089 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(199003)(377454003)(479174004)(24454002)(189002)(36756003)(106356001)(15975445007)(19580395003)(33656002)(64706001)(5004730100002)(189998001)(4001540100001)(47776003)(10710500005)(65806001)(68736005)(77096005)(97736004)(40100003)(110136002)(50466002)(65956001)(4001350100001)(5001860100001)(7110500001)(5008740100001)(64126003)(122386002)(5007970100001)(81156007)(23676002)(105586002)(5001830100001)(66066001)(5001960100002)(2420400006)(80316001)(42186005)(83506001)(86362001)(2950100001)(87976001)(77156002)(87266999)(46102003)(59896002)(92566002)(76176999)(54356999)(50986999)(65816999)(101416001)(62966003)(85282002)(336755003)(18886065003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR11MB0679; H:decina.local; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: bluetreble.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWTJQUjExTUIwNjc5OzIzOjlXdS9sUEdBTFJTdFA1bTJmcEFUYUw2dnp6?= =?utf-8?B?RHU2ZmJsdCsrWmx6TGtqeXNZTDhvbytwUm1ZdktXaUczN3NZL2o3NkhGT09R?= =?utf-8?B?UURZWDlQdmVneGZ4bjkvaXNoaHNXcjVDVjJwdllWSG00Z0hxY1BvbE9oNzBo?= =?utf-8?B?M3YxaW1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dEhzQ3pMR3Zic291OXBZSkUyRnA3UndMcngx?= =?utf-8?B?MVpYRWd6SWpEd01sSGt1WUNMOEZCUUVFd3dkRUtnV2gycDdSRmpSZ3NlUXM2?= =?utf-8?B?cUlIZU05eU5YSkZ4MVg2ZDZwaDMrVDQ5UmFtVHBUTVUvSnA3OXBWWVdUV0Uw?= =?utf-8?B?a3c9PQ==?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR11MB0679; 5:riepIHQMzZVCzL7OTuqgKbEV1JOTPshGaGhxLEQ6cl1jLf5gtt0va/1mysfYHEhmN4rwMJYUy7PEErZI1AMjBwHmzK6ijBcGJD+S0K3qv0ySafwsxSDSYMVt8zegEqvaXEnzv7QjeCnfj8sjZjbY+g==; 24:MFz7AyTKBJyuLRl2LDDa0ajzbUiYg4IYFNg1CDM/yRoB1CNJECC3JTMOmkgWIcQD9RYWlOjp7ikpCz90idOJV3YkJBTfGMAxNUVHQF8Jn30=; 20:bAYX0GDqZZAlPyro0vvoNISFpcFDBZNUA0I8GLr872Kg5mkSbelsNKUb/qaEgdXvBirixC7NacfFl0EJcyzGyw== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: bluetreble.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2015 19:13:24.0173 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR11MB0679 X-Pg-Spam-Score: -1.9 (-) 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 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: >>> 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? >> >> Not quite. Any unique index that isn't partial and isn't a functional >> index can satisfy a foreign key. That means that if you change a field >> that is in ANY unique index that update becomes a FOR KEY UPDATE. > > Interesting, do you know if that is mentioned in the documentation > somewhere? (I couldn't find it) http://www.postgresql.org/docs/9.4/static/ddl-constraints.html#DDL-CONSTRAINTS-FK does say this: "A foreign key must reference columns that either are a primary key or form a unique constraint." So you can kind of infer it. It could probably be more explicitly mentioned somewhere though. Care to suggest a doc change? >>> -- 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" >> >> 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 (sorry for > the wrapping): I'm not sure. Perhaps Kevin Grittner (author of serializable patch) can shed some light. -- Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX Experts in Analytics, Data Architecture and PostgreSQL Data in Trouble? Get it in Treble! http://BlueTreble.com -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general