Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XAB6B-0007Q2-AB for pgsql-performance@arkaria.postgresql.org; Thu, 24 Jul 2014 04:57:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XAB6A-0000qA-2w for pgsql-performance@arkaria.postgresql.org; Thu, 24 Jul 2014 04:57:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XAB69-0000q4-6u for pgsql-performance@postgresql.org; Thu, 24 Jul 2014 04:57:45 +0000 Received: from mout.kundenserver.de ([212.227.17.24]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XAB64-0000US-5T for pgsql-performance@postgresql.org; Thu, 24 Jul 2014 04:57:44 +0000 Received: from ayaki.localdomain (58-7-92-198.dyn.iinet.net.au [58.7.92.198]) by mrelayeu.kundenserver.de (node=mreue105) with ESMTP (Nemesis) id 0M25gB-1WMLUi44vD-00u4tL; Thu, 24 Jul 2014 06:57:37 +0200 Message-ID: <53D0923B.7050501@2ndquadrant.com> Date: Thu, 24 Jul 2014 12:57:31 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Reza Taheri , "pgsql-performance@postgresql.org" Subject: Re: High rate of transaction failure with the Serializable Isolation Level References: In-Reply-To: X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Provags-ID: V02:K0:pe74f+PrNWPnPU+WwZMZySl/xZ/xnjCgKXgXlb0GlEZ sm8H1zfhbSHLUwyeCz5htSDvtmiUePlZAQY8oJIGnb9+UPmZh5 eUHa3xQ7CjcKSc3vlUj4yGGMwLSuX7lYJnDsqUHP9VqrA6B1IA Wcjzrg0U3qHWJgOYYJ78CQ5qoxRSeDbor8f4WEz3HcWNFLZl+S F/E6IJC7KYRkkJl37yoP0KhfVM1JEO9kAyKPznDApn4tmbtiQm FtDXDj9Wukc2olUAIhAgxwGruHLIPySV7kT//5oIOHw/k87Lkg LCh90EcSXybkFCW1Y9lVm9zV14BCjRWZxwuNRkinP9A57if5AZ UOLMZx/sMLKLAns0/FBNhk8Jk/QkYg4jvpQSMFpMo X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 07/24/2014 09:18 AM, Reza Taheri wrote: > What is unusual is that the majority of the failures occur in a > statement that should not have any isolation conflicts. About 17K of > failures are from the statement below: It's not just that statement that is relevant. At SERIALIZABLE isolation the entire transaction's actions must be considered, as must the conflicting transaction. > This doesn’t make sense since at any given time, only one transaction > might possibly be accessing the row that is being updated. There should > be no conflicts if we have row-level locking/isolation. Is that statement run standalone, or as part of a larger transaction? > The second most common conflict happens 7.6K times in the statement below: ... > I don’t understand why an insert would hit a serialization conflict If the INSERTing transaction previously queried for a key that was created by a concurrent transaction this can occur as there is no serialization execution order of the transactions that could produce the same result. This doesn't produce exactly the same error, but demonstrates one such case: regress=> CREATE TABLE demo (id integer primary key, value integer); CREATE TABLE regress=> INSERT INTO demo(id, value) VALUES (1, 42); INSERT 0 1 then regress=> BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; BEGIN regress=> SELECT id FROM demo WHERE id = 2; id ---- (0 rows) session1=> BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; BEGIN session2=> BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; BEGIN session1=> SELECT id FROM demo WHERE id = 2; id ---- (0 rows) session2=> SELECT id FROM demo WHERE id = 3; id ---- (0 rows) session1=> INSERT INTO demo VALUES (3, 43); INSERT 0 1 session2=> INSERT INTO demo VALUES (2, 43); INSERT 0 1 session2=> COMMIT; COMMIT session1=> COMMIT; ERROR: could not serialize access due to read/write dependencies among transactions DETAIL: Reason code: Canceled on identification as a pivot, during commit attempt. HINT: The transaction might succeed if retried. > Does PGSQL raise locks to page level when we run with > SQL_TXN_SERIALIZABLE?