Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TOMz6-0007Mi-2p for pgsql-performance@postgresql.org; Wed, 17 Oct 2012 06:20:04 +0000 Received: from mail-pa0-f46.google.com ([209.85.220.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TOMz0-0005V2-CT for pgsql-performance@postgresql.org; Wed, 17 Oct 2012 06:20:03 +0000 Received: by mail-pa0-f46.google.com with SMTP id hz1so6732847pad.19 for ; Tue, 16 Oct 2012 23:19:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=thnnm5u2Y1xlsUGMiqY9II1Dy6Es4eiKh2pW9h2Ok08=; b=GoVuMcCkIoPY61MMDR/rcQ0nQH8hIfWFkIh0WEtSTzoCLTk6Fo3iLTY/j3yY5KPN7Y Oiau/9mYTnXq08Q+bdp+m04lSCH55aJjRHGq/49xUXuQ1CQfMZey8wT4ykwy+jU4WlxQ C2nBkH5AzLpwqd6rfBWaa3mNp3ZPA0Y0+f8HPwGqb+0dlypVYn+e8KjvK9PZVah2vbRz D32UO4JkNAUVG35OBA5WBDwOxI1CKroSJDGWUM1vo92ybes9u6XlvJZ/53uBYtiFjWZI ScdeH60ZWM6/E86eKkLFq5x91oT1/F8iuxkPdEzXwDEC96O0iHUU6F1IN2Zv15oG9Nr5 mHeA== Received: by 10.68.213.199 with SMTP id nu7mr54101601pbc.75.1350454795553; Tue, 16 Oct 2012 23:19:55 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id pj10sm11992115pbb.46.2012.10.16.23.19.51 (version=SSLv3 cipher=OTHER); Tue, 16 Oct 2012 23:19:54 -0700 (PDT) Message-ID: <507E4E05.9040400@ringerc.id.au> Date: Wed, 17 Oct 2012 14:19:49 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: Filippos Kalamidas CC: Sylvain CAILLET , pgsql-performance@postgresql.org Subject: Re: Slow Delete : Seq scan instead of index scan References: <507D1631.9050904@ringerc.id.au> <277219265.3802606.1350375882663.JavaMail.root@alaloop.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQkC8qqaTZEw4WVKRNZjeKzcl4/jhTjfBh4s12+RrD9dPyceCSR93NmY0mOfr8TlUGv8HRN2 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201210/225 X-Sequence-Number: 48184 On 10/16/2012 04:41 PM, Filippos Kalamidas wrote: > the first thing you should probably do is run an 'analyze' on one of > these tables and then run again the delete statement. if there are no > stats for these tables, it's normal not to have very good plans. Yep, and the fact that the stats are that bad suggests that autovaccum probably isn't running, or isn't running often enough. If you have a high INSERT/UPDATE/DELETE load, then turn autovacuum up on that table. See: http://www.postgresql.org/docs/current/static/routine-vacuuming.html http://www.postgresql.org/docs/current/static/runtime-config-autovacuum.html If the table is badly bloated it might be worth running "VACUUM FULL" on it or (if you're on PostgreSQL 8.4 or below) instead CLUSTER the table on an index, as "VACUUM FULL" is very inefficient in 8.4 and older (I think; I might be misremembering the versions). Please specify your PostgreSQL version in all questions. See https://wiki.postgresql.org/wiki/Slow_Query_Questions -- Craig Ringer