Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQ2Qj-00045C-MD for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Sep 2021 07:00:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mQ2Qg-0005d3-D8 for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Sep 2021 07:00:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQ2Qg-0005cv-4s for pgsql-bugs@lists.postgresql.org; Tue, 14 Sep 2021 07:00:30 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQ2QZ-0003OS-1X for pgsql-bugs@lists.postgresql.org; Tue, 14 Sep 2021 07:00:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ob9eBcUaZT3U9anO/hvo9GqEgBLGCsky4+g9nX6uVsM=; b=VpoD0eadFt5E26kY9k6Ibyq4T8 Z4nJeGR2jkFue5qYE6dQTkX6nF+oasqnzp0JXZbmNRbVaerR+k/Z8TCttMIur/n55wNWDKET1bgfA AU4xEOiSoetTbtKC9t0CuG6fAY1U1pk7cWr66kMPH7CGiNgCmydn6CfOMnuboY+neqCY=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mQ2QW-0003DZ-1N; Tue, 14 Sep 2021 09:00:20 +0200 Date: Tue, 14 Sep 2021 09:00:19 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: "tanghy.fnst@fujitsu.com" Cc: PostgreSQL mailing lists Subject: Re: [BUG] Deadlock detected when update with multiple clients Message-ID: <20210914070019.GA10022@depesz.com> Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Sep 14, 2021 at 03:03:40AM +0000, tanghy.fnst@fujitsu.com wrote: > I met a deadlock when I update amounts of text-type data with multiple clients. > And there's no deadlock if I set autovacuum to off. Error messages about the > deadlock are as follows. Autovacuum is red herring. Your queries deadlock because they update all the rows in random order, so sometimes it goes into deadlock condition. This is known, is not a bug. When you're doing multiple updates that might update the same rows (and yours definitely do), it is important to update them in the same order. Or lock before. It's hard to provide solid advise in here, since your test case is clearly bogus - there is no reason to run more than 1 update of whole table, with the same update clause, at once. depesz