Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL exclusive lock stops application

My applications tests are pretty hard on the database. They run create, drop and alter table statements. However, I would still expect postresql to handle these even in the case of a deadlock (i.e detect the lock and trow one thread out). I am not running requests concurrently either.

However, in my case it just freezes and I have to manually kill them off manually (it works if I change the order of running slightly though, but this does not give me confidence). The locks show that a create table statement has an exclusive lock and a transaction has one too.

Has anyone experienced anything similar? Are there any server settings that can help out? Or just any advise?

like image 894
David Raznick Avatar asked Feb 28 '23 12:02

David Raznick


1 Answers

PostgreSQL automatically detects deadlocks. Most likely, you are only blocking on some statement somewhere that hasn't finished. A deadlock only occurs if two statements are waiting for each other.

If you examine your "lock tree" down to the root (d blocking on b blocking on a has a at the root), you will most likely find a transaction somewhere that's either taking a long time to run, or that is not properly committed but just sits in "idle-in-transaction" mode.

Since you mention threads though - mind that all client libraries are not necessarily threadsafe on the client side.

like image 110
Magnus Hagander Avatar answered Mar 03 '23 01:03

Magnus Hagander