Re: Unexpected deadlock across two separate rows, using Postgres 17 and Django's select_for_update()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Shaheed Haque <shaheedhaque(at)gmail(dot)com>
Cc: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Unexpected deadlock across two separate rows, using Postgres 17 and Django's select_for_update()
Date: 2026-03-07 11:45:29
Message-ID: 30226.1772883929@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Shaheed Haque <shaheedhaque(at)gmail(dot)com> writes:
> How can there be a deadlock between updates to different rows (as per the
> bolded WHERE clauses)?

In isolation, there couldn't be ... but you've told us nothing of
what these transactions did beforehand. The simplest explanation
is that each one is already holding a lock on the row the other
one wants.

Maybe you are not committing between row updates?

If you have no better debugging ideas, try setting log_statements = all
and then examining everything the transactions did up to the failure.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2026-03-07 14:29:48 Re: How to properly use TRIM()?
Previous Message Shaheed Haque 2026-03-07 09:24:32 Unexpected deadlock across two separate rows, using Postgres 17 and Django's select_for_update()