Sample Header Ad - 728x90

Postgres 9.5 deadlock with many updates on a table + many "select for update" on another table

2 votes
1 answer
631 views
I have two tables: "machines" and "magictools". "magictools" refers to "machines" with a foreign key. I face a deadlock problem while executing many of these requests: //this will produce an "AccessExclusiveLock" of type "tuple" on machines SELECT FROM * machines FOR UPDATE where id = :id; //this will produce a "RowExclusiveLock" on magictools and a "RowShareLock" on machines UPDATE magictools SET collections = "large-json" where id = :id As far I understood running many of these request produces deadlocks. Maybe it's only the updates who are performing this, I don't know. How should I avoid the deadlocks in this case? I have many indexes on these tables, maybe I have too many indexes? Below is the report of pg_activity when the problem happened. I do not understand the different modes and lock types, and, just, what happens here? Is it possible that just an update without any transaction causes a deadlock? deadlock trace link
Asked by Slim (291 rep)
Dec 17, 2020, 01:33 PM
Last activity: Dec 17, 2020, 02:48 PM