Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gFJk1-0006fX-Ic for pgsql-general@arkaria.postgresql.org; Wed, 24 Oct 2018 14:02:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gFJk0-0007PW-1w for pgsql-general@arkaria.postgresql.org; Wed, 24 Oct 2018 14:02:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gFJjz-0007PO-Px for pgsql-general@lists.postgresql.org; Wed, 24 Oct 2018 14:02:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gFJjs-0007bS-FN for pgsql-general@lists.postgresql.org; Wed, 24 Oct 2018 14:02:31 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w9OE2HUb024276; Wed, 24 Oct 2018 10:02:18 -0400 From: Tom Lane To: Michal Merta cc: pgsql-general@lists.postgresql.org Subject: Re: Deadlock while doing VACUUM and DROP In-reply-to: <21fe894d-4fb8-974d-cdd6-2b252852ce76@greycortex.com> References: <21fe894d-4fb8-974d-cdd6-2b252852ce76@greycortex.com> Comments: In-reply-to Michal Merta message dated "Wed, 24 Oct 2018 15:53:29 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19802.1540389737.1@sss.pgh.pa.us> Date: Wed, 24 Oct 2018 15:02:17 +0100 Message-ID: <19803.1540389737@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michal Merta 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