On 2024-09-20 14:11:38 -0700, Adrian Klaver wrote: > On 9/20/24 1:01 PM, veem v wrote: > > Able to reproduce this deadlock graph as below. Now my question is , > > this is a legitimate scenario in which the same ID can get inserted from > > multiple sessions and in such cases it's expected to skip that (thus "On > > conflict Do nothing" is used) row. But as we see it's breaking the code > > Yeah, as I see it that would not work with concurrent uncommitted sessions > as it would be unresolved whether a conflict actually exists until at least > one of the sessions completes. > > > with deadlock error during race conditions where a lot of parallel > > threads are operating. So how should we handle this scenario? Will > > setting the "lock_timeout" parameter at session level will help us > > anyway here? > > Serializable transaction?: > > https://www.postgresql.org/docs/current/transaction-iso.html#XACT-SERIALIZABLE Doesn't help here, at least not directly. It would help indirectly because isolation level serializable makes it very proable that serialization errors occur. So an application designed for serializable would have some kind of retry logic already in place. SO that leads as to another solution: Retry each batch (possibly after reducing the batch size) until it succeeds. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@xxxxxx | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
Attachment:
signature.asc
Description: PGP signature