Re: deadlock while doing VACUUM and DROP

From: "Pavan Deolasee" <pavan(dot)deolasee(at)gmail(dot)com>
To: Jan Urbański <j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl>
Cc: "Postgres - Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: deadlock while doing VACUUM and DROP
Date: 2008-05-16 04:33:05
Message-ID: 2e78013d0805152133g53d2a1b3sd75ede11d4b9ece6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, May 16, 2008 at 5:24 AM, Jan Urbański
<j(dot)urbanski(at)students(dot)mimuw(dot)edu(dot)pl> wrote:
>
> ERROR: deadlock detected
> DETAIL: Process 25423 waits for AccessExclusiveLock on relation 16386 of
> database 1; blocked by process 25428.
> Process 25428 waits for AccessShareLock on relation 16390 of database
> 1; blocked by process 25423.
> Process 25423: drop table manuale ;
> Process 25428: autovacuum: VACUUM ANALYZE public.manuale

I looked at it briefly. ISTM that the main relation and the toast
relation is getting into a deadlock. VACUUM first vacuums the main
relation, commits the transaction but *keeps* the
ShareUpdateExclusiveLock on the main relation. It then vacuums the
toast relation which requires ShareUpdateExclusiveLock on the toast
relation.

If at the same time, another backend drops the main relation. Because
of dependency, the toast relation is dropped first. So the other
backend takes AccessExclusiveLock on the toast relation. It then tries
to drop the main relation, asks for AccessExclusiveLock on the main
relation and gets into a deadlock with the first process vacumming the
relation.

I think we can fix it by making sure that locks on the to-be-deleted
and all the dependent objects are taken first, in an order that would
prevent the deadlock. Alternatively, we can just acquire
AccessExclusiveLock on the main relation before proceeding with the
recursive deletion. That would solve this case, but may be there are
other similar deadlocks waiting to happen. Also I am not sure if the
issue is big enough to demand the change.

Thanks,
Pavan

--
Pavan Deolasee
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2008-05-16 07:47:57 Re: deadlock while doing VACUUM and DROP
Previous Message Xiao Meng 2008-05-16 02:42:05 [GSoC08]some detail plan of improving hash index