Re: Deadlock while doing VACUUM and DROP

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michal Merta <michal(dot)merta(at)greycortex(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Deadlock while doing VACUUM and DROP
Date: 2018-10-24 14:02:17
Message-ID: 19803.1540389737@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michal Merta <michal(dot)merta(at)greycortex(dot)com> writes:
> I encountered deadlock during DROP TABLE statement:

> 2018-10-23 14:49:55 CEST psql > ERROR: deadlock detected
> 2018-10-23 14:49:55 CEST psql > DETAIL: Process 89171 waits for
> AccessExclusiveLock on relation 17582 of database 16390; blocked by
> process 50837.
> Process 50837 waits for AccessShareLock on relation 20767 of
> database 16390; blocked by process 89171.
> Process 89171: DROP TABLE IF EXISTS sm.tasks;
> Process 50837: autovacuum: ANALYZE sm.tasks

Hm, there's more to that than meets the eye, because the locks were on
two different tables. Have you checked which tables are involved,
eg "select 20767::regclass"?

> Is there anything I can do make sure that DDL statement won't be
> canceled due to collision with autovaccum?

I suspect your DDL transaction was getting exclusive locks on multiple
tables. That's always hazardous. It might be easier to retry the
DDL than try to guarantee no deadlock. Or break it up into separate
transactions for each table.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Steve Clark 2018-10-24 14:10:47 Re: no libpq.pc for Centos 6 or Centos 7
Previous Message Michal Merta 2018-10-24 13:53:29 Deadlock while doing VACUUM and DROP