Thread: deadlock with vacuum full on 7.4.5
I have a table that is usually really small (currently 316 rows) but goes through spasams of updates in a small time window. Therefore I have a vacuum full run every hour on this table. Last night one of these vacuum fulls deadlocked with a query on this table. Both were stuck doing nothing until I did a kill -INT on the backends doing the vacuum. So my questions: 1) What can I do to avoid this? 2) What do I do next time this happens to get more debugging info out of the situation? My postgres version: PostgreSQL 7.4.5 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Joseph Shraibman <jks@selectacast.net> writes: > Last night one of these vacuum fulls deadlocked with a query on this > table. Both were stuck doing nothing until I did a kill -INT on the > backends doing the vacuum. > So my questions: > 1) What can I do to avoid this? > 2) What do I do next time this happens to get more debugging info out of > the situation? Look in pg_locks and pg_stat_activity. I think it is highly unlikely that there was a deadlock inside the database. Far more likely that both jobs were waiting on some idle-in-transaction client whose transaction was holding a lock on the table. regards, tom lane
Why then when I did a kill -INT on the vacuuming backends did everything unfreeze? Tom Lane wrote: > Joseph Shraibman <jks@selectacast.net> writes: > >>Last night one of these vacuum fulls deadlocked with a query on this >>table. Both were stuck doing nothing until I did a kill -INT on the >>backends doing the vacuum. > > >>So my questions: >>1) What can I do to avoid this? >>2) What do I do next time this happens to get more debugging info out of >>the situation? > > > Look in pg_locks and pg_stat_activity. > > I think it is highly unlikely that there was a deadlock inside the > database. Far more likely that both jobs were waiting on some > idle-in-transaction client whose transaction was holding a lock > on the table. > > regards, tom lane
Joseph Shraibman <jks@selectacast.net> writes: > Why then when I did a kill -INT on the vacuuming backends did everything > unfreeze? You could have had other stuff backed up behind the VACUUM FULL lock requests. It's not impossible that you had a deadlock *outside* the database, that is some wait loop that is partially within and partially outside the DB. But if you want me to believe there's a bug in our deadlock detector, you're going to have to offer some actual evidence... regards, tom lane
That is what I wanted to know, how to get the evidence for next time. Tom Lane wrote: > Joseph Shraibman <jks@selectacast.net> writes: > >>Why then when I did a kill -INT on the vacuuming backends did everything >>unfreeze? > > > You could have had other stuff backed up behind the VACUUM FULL lock > requests. > > It's not impossible that you had a deadlock *outside* the database, > that is some wait loop that is partially within and partially outside > the DB. But if you want me to believe there's a bug in our deadlock > detector, you're going to have to offer some actual evidence... > > regards, tom lane
Joseph Shraibman wrote: > That is what I wanted to know, how to get the evidence for next time. > select * from pg_locks Regards Gaetano Mendola
I have figured out the problem. When I do a BEGIN; and then a SELECT an AccessShareLock is obtained on the table, and then not released until the transaction is over. Then the vacuum comes in and tries to acquire an exclusive lock, and in the process blocks any readers who are trying to SELECT on the same table. My app reads from both db connections in the same thread, thus the deadlock occurs. So why isn't the AccessShareLock dropped as soon as the SELECT is over? On Tue, 12 Oct 2004, Tom Lane wrote: > Joseph Shraibman <jks@selectacast.net> writes: > > Last night one of these vacuum fulls deadlocked with a query on this > > table. Both were stuck doing nothing until I did a kill -INT on the > > backends doing the vacuum. > > > So my questions: > > 1) What can I do to avoid this? > > 2) What do I do next time this happens to get more debugging info out of > > the situation? > > Look in pg_locks and pg_stat_activity. > > I think it is highly unlikely that there was a deadlock inside the > database. Far more likely that both jobs were waiting on some > idle-in-transaction client whose transaction was holding a lock > on the table. > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend >
jks@selectacast.net writes: > So why isn't the AccessShareLock dropped as soon as the SELECT is over? In general, locks are held till transaction commit. See any basic database text for the reasons why this is a good idea. regards, tom lane