Re: [BUG] Deadlock detected when update with multiple clients

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: "tanghy(dot)fnst(at)fujitsu(dot)com" <tanghy(dot)fnst(at)fujitsu(dot)com>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: [BUG] Deadlock detected when update with multiple clients
Date: 2021-09-14 07:00:19
Message-ID: 20210914070019.GA10022@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Sep 14, 2021 at 03:03:40AM +0000, tanghy(dot)fnst(at)fujitsu(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2021-09-14 09:47:06 BUG #17192: The csvlog is corrupted
Previous Message tanghy.fnst@fujitsu.com 2021-09-14 03:03:40 [BUG] Deadlock detected when update with multiple clients