Postgresql Deadlock - what does "while rechecking updated tuple" mean?
Even an answer to the following question would help: what's the difference between updating tuple and rechecking updated tuple?


I will take you up on this part.  When PostgreSQL finds a row that meets the WHERE clause to be updated, but that tuple has already been modified by a not-yet-committed transaction, it will wait for that transaction to commit and then recheck that the new version of the row still meets the WHERE clause.

So 31391 was wanting to update a tuple that 25788 had already updated (presumably in a prior statement in 25788's transaction), and was waiting for 25788 to finish so it could recheck that it still wanted to update it.

25788 was waiting or 31391 to finish, but we don't know why it was waiting for as it didn't log a CONTEXT line.

Can you tell if 25788 was implementing the 3rd step of thread #1, or is it implementing thread #2? 

Does your thread #2 issue its 25788-like query each in its own transaction?