Avoiding deadlocks

I’ve never done duplicate inserts quite exactly like this but when writing from dozens of python containers to thousands of mutually overlapping tables I avoided deadlocks by sorting the tables’ order per-transaction. In this way table mutation occurs along a DAG and while a transaction can block another one, it won’t deadlock because if they conflicted on a prior (lower sorted) lock/table they would have blocked there instead. Idk if that’s possible for your data but that’s my Timescale deadlock avoidance strategy.

1 Like