Csaba Nagy <nagy@xxxxxxxxxxxxxx> writes: >> Can you explain why sorting by ID would make a difference as I don't >> understand why what you are suggesting should make a difference? > > Because I guess id is your primary key, and that would make your > transactions always update the same rows in the same order. If the deadlocks occur because different transactions actually try to update the same rows concurrently, then this is an appropriate solution. However I wonder if Gavin is getting bitten by foreign key deadlocks. Is there any foreign key reference from the stats table to other tables? regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq