Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZwbB3-0004Rm-RF for pgsql-performance@arkaria.postgresql.org; Wed, 11 Nov 2015 19:35:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZwbB3-0002aV-CG for pgsql-performance@arkaria.postgresql.org; Wed, 11 Nov 2015 19:35:29 +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.84) (envelope-from ) id 1Zwb9N-0006Cb-3w for pgsql-performance@postgresql.org; Wed, 11 Nov 2015 19:33:45 +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.84) (envelope-from ) id 1Zwb9G-0004ya-Ef for pgsql-performance@postgresql.org; Wed, 11 Nov 2015 19:33:44 +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 tABJXZ5O017090; Wed, 11 Nov 2015 14:33:35 -0500 From: Tom Lane To: Massalin Yerzhan cc: pgsql-performance@postgresql.org Subject: Re: Simple delete query is taking too long (never ends) In-reply-to: References: Comments: In-reply-to Massalin Yerzhan message dated "Thu, 12 Nov 2015 01:09:36 +0600" Date: Wed, 11 Nov 2015 14:33:35 -0500 Message-ID: <17089.1447270415@sss.pgh.pa.us> X-Pg-Spam-Score: -2.2 (--) 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 Massalin Yerzhan writes: > I'm having an issue. The query never ends: > delete from bb_gamelist_league; 9 times out of 10, the answer to this type of problem is that you have some table referencing this one by a foreign key, and the referencing column is not indexed. PG doesn't require such an index, but lack of one will mean that retail checks or deletions of referencing rows are really slow. If you're not sure which table is the problem, try doing an EXPLAIN ANALYZE of a DELETE that will only remove a few rows. You should see some time blamed on a trigger associated with the FK constraint. 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