pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed[BUG] Deadlock detected when update with multiple clients
2+ messages / 2 participants
[nested] [flat]
* [BUG] Deadlock detected when update with multiple clients
@ 2021-09-14 03:03 tanghy.fnst@fujitsu.com <tanghy.fnst@fujitsu.com>
2021-09-14 07:00 ` Re: [BUG] Deadlock detected when update with multiple clients hubert depesz lubaczewski <depesz@depesz.com>
0 siblings, 1 reply; 2+ messages in thread
From: tanghy.fnst@fujitsu.com @ 2021-09-14 03:03 UTC (permalink / raw)
To: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Hi
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.
2021-09-14 09:18:40.392 CST [428452] ERROR: deadlock detected
2021-09-14 09:18:40.392 CST [428452] DETAIL: Process 428452 waits for ShareLock on transaction 1725; blocked by process 428455.
Process 428455 waits for ShareLock on transaction 1723; blocked by process 428452.
Process 428452: UPDATE tbl SET body = upper(body);
Process 428455: UPDATE tbl SET body = upper(body);
2021-09-14 09:18:40.392 CST [428452] HINT: See server log for query details.
2021-09-14 09:18:40.392 CST [428452] CONTEXT: while rechecking updated tuple (0,1) in relation "tbl"
2021-09-14 09:18:40.392 CST [428452] STATEMENT: UPDATE tbl SET body = upper(body);
I'm not sure if I used it inappropriately, or it's unexpected. Could someone
take a look at this problem?
Attach a script to reproduce it. It took about 2~3 minutes to run it on my
machine.
FYI, I found this problem on HEAD and I could reproduce at PG14 and PG13. I
didn't try other versions.
Regards
Tang
Attachments:
run.sh (application/octet-stream, 643B) download
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [BUG] Deadlock detected when update with multiple clients
2021-09-14 03:03 [BUG] Deadlock detected when update with multiple clients tanghy.fnst@fujitsu.com <tanghy.fnst@fujitsu.com>
@ 2021-09-14 07:00 ` hubert depesz lubaczewski <depesz@depesz.com>
0 siblings, 0 replies; 2+ messages in thread
From: hubert depesz lubaczewski @ 2021-09-14 07:00 UTC (permalink / raw)
To: tanghy.fnst@fujitsu.com <tanghy.fnst@fujitsu.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2021-09-14 07:00 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 03:03 [BUG] Deadlock detected when update with multiple clients tanghy.fnst@fujitsu.com <tanghy.fnst@fujitsu.com>
2021-09-14 07:00 ` hubert depesz lubaczewski <depesz@depesz.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox