Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YmwFT-00082A-0v for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Apr 2015 03:31:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YmwFS-0005bd-G5 for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Apr 2015 03:31:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YmwFQ-0005bV-OF for pgsql-hackers@postgresql.org; Tue, 28 Apr 2015 03:31:48 +0000 Received: from mail-pa0-x229.google.com ([2607:f8b0:400e:c03::229]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YmwFN-00017N-CY for pgsql-hackers@postgresql.org; Tue, 28 Apr 2015 03:31:47 +0000 Received: by pabtp1 with SMTP id tp1so150493293pab.2 for ; Mon, 27 Apr 2015 20:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:reply-to:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=zFqHOqeXetfKfv62SDjpJ/OMj5y2l2OEVDXUGwZUy10=; b=Nw+fDAK67khtNFFYSCDJhKROHZeMRSjVRyPWj1ojt/osOHk2bS/vB0U1sXfvficbu/ 5QPbY3ISJdqXi4+q6W3v+6X9G9OjrMaZIp1DIlQN4bGJpYIudy4RD3F6mPdDGHaD3ovS kBScgrFOwqRIZyA7iCDzygqNxXohgcoD8rHNQXl4v0ZPvF3EgEcdyP/z4EAV2Smi34pV y/2sIa+Q4aLt4ay/cYE5j4yJoeG0gn5LW95zHFyKaasxhgACPfa2O0MQOd4yCgepSD1p 7r1MEZPKpEcyyDr99WbPxhCR4DcFqC04JTIZomQ5Ura0svedUAbasprhuoWbBYGD+lEv E1qw== X-Received: by 10.70.47.9 with SMTP id z9mr28313937pdm.69.1430191903027; Mon, 27 Apr 2015 20:31:43 -0700 (PDT) Received: from [172.20.101.172] ([66.201.48.54]) by mx.google.com with ESMTPSA id cu8sm20881510pad.1.2015.04.27.20.31.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Apr 2015 20:31:41 -0700 (PDT) Message-ID: <553EFF0D.4040903@iki.fi> Date: Mon, 27 Apr 2015 20:31:25 -0700 From: Heikki Linnakangas Reply-To: hlinnaka@iki.fi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 MIME-Version: 1.0 To: Peter Geoghegan , Andres Freund , Jeff Janes , Stephen Frost , Dean Rasheed , Bruce Momjian CC: Pg Hackers Subject: Re: INSERT ... ON CONFLICT UPDATE/IGNORE 4.0 References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.1 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 04/27/2015 07:02 PM, Peter Geoghegan wrote: > So, this can still happen, but is now happening less often than > before, I believe. On a 16 core server, with continual 128 client > jjanes_upsert exclusion constraint only runs, with fsync=off, I > started at this time: > > 2015-04-27 21:22:28 UTC [ 0 ]: LOG: database system was shut down at > 2015-04-27 21:22:25 UTC > 2015-04-27 21:22:28 UTC [ 0 ]: LOG: database system is ready to > accept connections > 2015-04-27 22:47:20 UTC [ 0 ]: LOG: autovacuum launcher started > 2015-04-27 22:47:21 UTC [ 0 ]: LOG: autovacuum launcher started > > Finally, with ON CONFLICT UPDATE (which we don't intend to support > with exclusion constraints anyway), the torture testing finally > produces a deadlock several hours later (due to having "livelock > insurance" [1]): > > 2015-04-28 00:22:06 UTC [ 0 ]: LOG: autovacuum launcher started > 2015-04-28 00:37:24 UTC [ 432432057 ]: ERROR: deadlock detected > 2015-04-28 00:37:24 UTC [ 432432057 ]: DETAIL: Process 130628 waits > for ShareLock on transaction 432432127; blocked by process 130589. > Process 130589 waits for ShareLock on speculative token 13 of > transaction 432432057; blocked by process 130628. > Process 130628: insert into upsert_race_test (index, count) > values ('7566','-1') on conflict > update set count=TARGET.count + EXCLUDED.count > where TARGET.index = EXCLUDED.index > returning count > Process 130589: insert into upsert_race_test (index, count) > values ('7566','1') on conflict > update set count=TARGET.count + EXCLUDED.count > where TARGET.index = EXCLUDED.index > returning count > 2015-04-28 00:37:24 UTC [ 432432057 ]: HINT: See server log for query details. > 2015-04-28 00:37:24 UTC [ 432432057 ]: CONTEXT: while checking > exclusion constraint on tuple (3,36) in relation "upsert_race_test" > 2015-04-28 00:37:24 UTC [ 432432057 ]: STATEMENT: insert into > upsert_race_test (index, count) values ('7566','-1') on conflict > update set count=TARGET.count + EXCLUDED.count > where TARGET.index = EXCLUDED.index > returning count > > ON CONFLICT UPDATE will only ever use unique indexes, and so is not affected. > > Given that exclusion constraints can only be used with IGNORE, and > given that this is so hard to recreate, I'm inclined to conclude that > it's acceptable. It's certainly way better than risking livelocks by > not having "deadlock insurance". This is a ridiculously CPU-bound > workload, with extreme and constant contention. I'd be surprised if > there were any real complaints from the field in practice. > > Do you think that this is acceptable, Heikki? I thought we had an ironclad scheme to prevent deadlocks like this, so I'd like to understand why that happens. - Heikki -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers