Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WdQGb-0000Gs-Ve for pgsql-performance@arkaria.postgresql.org; Thu, 24 Apr 2014 20:29:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WdQGa-00011N-Qt for pgsql-performance@arkaria.postgresql.org; Thu, 24 Apr 2014 20:29:08 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WdQGZ-00011G-Jn for pgsql-performance@postgresql.org; Thu, 24 Apr 2014 20:29:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WdQGW-000395-Kv for pgsql-performance@postgresql.org; Thu, 24 Apr 2014 20:29:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s3OKT0cn028605; Thu, 24 Apr 2014 16:29:00 -0400 From: Tom Lane To: Jonatan Evald Buus cc: pgsql-performance@postgresql.org Subject: Re: Poor performance for delete query In-reply-to: References: Comments: In-reply-to Jonatan Evald Buus message dated "Thu, 24 Apr 2014 21:42:41 +0200" Date: Thu, 24 Apr 2014 16:29:00 -0400 Message-ID: <28604.1398371340@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Jonatan Evald Buus writes: > We're currently having very poor performance for the following delete query. > DELETE FROM TopTable WHERE id IN (xx, yy, zz); > We've observed that it takes around 7 seconds under normal load to for each > row that's being from TopTable and several minutes pr deleted row under > heavy load. I'd really have to bet that you forgot to index one of the referencing tables. Are any of the foreign keys multi-column? If so you probably need a matching multi-column index, not just indexes on the individual referencing columns. > How do we track down the cause of the poorly performing delete query? EXPLAIN ANALYZE on a DELETE, for starters. That would isolate whether it's the DELETE itself or one of the foreign-key updates, and if the latter which one. It's a little bit difficult to see the exact plan being used for a foreign-key update query, but I think one way you could do it is to enable auto_explain with auto_explain.log_nested_statements turned on. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance