Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 801389FA5FC for ; Tue, 2 Oct 2007 19:40:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 57614-02-3 for ; Tue, 2 Oct 2007 19:40:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from copgpuniv.digitalglobe.com (ew-fw-out.digitalglobe.com [205.166.175.2]) by postgresql.org (Postfix) with ESMTP id 817AE9FA31B for ; Tue, 2 Oct 2007 19:40:14 -0300 (ADT) Received: from copgpuniv.digitalglobe.com (localhost.localdomain [127.0.0.1]) by copgpuniv.digitalglobe.com (PGP Universal) with ESMTP id DFE1E2A0357; Tue, 2 Oct 2007 16:40:10 -0600 (MDT) Received: from comailgate2.digitalglobe.com ([10.10.42.200]) by copgpuniv.digitalglobe.com (PGP Universal service); Tue, 02 Oct 2007 16:40:10 -0600 X-PGP-Universal: processed; by copgpuniv.digitalglobe.com on Tue, 02 Oct 2007 16:40:10 -0600 Received: from webmail.digitalglobe.com ([10.10.42.65]) by comailgate2.digitalglobe.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 2 Oct 2007 16:40:10 -0600 Received: from [10.9.103.42] ([10.9.103.42]) by webmail.digitalglobe.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 2 Oct 2007 16:40:10 -0600 Message-ID: <4702C8B7.5020701@digitalglobe.com> Date: Tue, 02 Oct 2007 15:39:51 -0700 From: Greg Williamson User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Giulio Cesare Solaroli Cc: pgsql-performance@postgresql.org Subject: Re: Newbie question about degraded performance on delete statement. References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 02 Oct 2007 22:40:10.0373 (UTC) FILETIME=[30722B50:01C80545] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/12 X-Sequence-Number: 27034 Giulio Cesare Solaroli wrote: > Hello everybody, > > I have just joined the list, as I am experiencing a degradation on > performances on my PostgreSQL instance, and I was looking for some > insights on how to fix/avoid it. > > What I have observed are impossibly high time on delete statements on > some tables. > > The delete statement is very simple: > delete from table where pk = ? > > The explain query report a single index scan on the primary key index, > as expected. > > I have run vacuum using the pgAdmin tool, but to no avail. > > I have also dropped and recreated the indexes, again without any benefit. > Make sure you run ANALYZE on the table in question after changes to make sure the stats are up to date. > I have later created a copy of the table using the "create table > table_copy as select * from table" syntax. > > Matching the configuration of the original table also on the copy > (indexes and constraints), I was able to delete the raws from the new > table with regular performances, from 20 to 100 times faster than > deleting from the original table. > > As another poster indicated, this sounds like foreign constraints where the postmaster process has to make sure there are no child references in dependent tables; if you are lacking proper indexing on those tables a sequential scan would be involved. Posting the DDL for the table in question and anything that might refer to it with an FK relationship would help the list help you. Try running the query with EXPLAIN ANALYZE ... to see what the planner says. Put this in a transaction and roll it back if you want to leave the data unchanged, e.g. BEGIN; EXPLAIN ANALYZE DELETE FROM foo WHERE pk = 1234; -- or whatever values you'd be using ROLLBACK; HTH, Greg Williamson Senior DBA GlobeXplorer LLC, a DigitalGlobe company Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information and must be protected in accordance with those provisions. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. (My corporate masters made me say this.)