Some database features, such as SELECT ... FOR UPDATE
and ON DELETE CASCADE
, are implicitly vulnerable to deadlocks because the database does not s
A few years wiser, I am revising the accepted answer to state that database deadlocks cannot be prevented.
If you are lucky enough to be able to break down database operations to only interact with a single table at a time (something that isn't always possible) then you are forced to choose between poor performance and the possibility of deadlocks. Pick your poison.