Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 43C2AB62D8F for ; Wed, 1 Jun 2011 03:14:21 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 63158-09 for ; Wed, 1 Jun 2011 06:14:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by mail.postgresql.org (Postfix) with ESMTP id 82E8EB62D8C for ; Wed, 1 Jun 2011 03:14:13 -0300 (ADT) Received: from [192.168.1.6] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0LbPII-1PmIWc1jX0-00kIfu; Wed, 01 Jun 2011 08:14:12 +0200 Message-ID: <4DE5D8B3.1070403@2ndQuadrant.com> Date: Wed, 01 Jun 2011 02:14:11 -0400 From: Greg Smith User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110505 Icedove/3.0.11 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Delete performance References: <6940CBA1-BB1C-4030-B425-2DE9135CEAE3@gmail.com> In-Reply-To: <6940CBA1-BB1C-4030-B425-2DE9135CEAE3@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:BFRRYepRm0dQFf+q9nHonSw2k4+lyGS714JZPIzW98k TgmPWUAxxEynkWn0rUNu7KlW7Ng2ygft/FBp0jHyoAtHAVDivs 5BrsGUDPsTnrcS4JLQTxgKGbBv4ZfgfORQfOdgEA96IDYCkz7F m2sr5h+Acgnn9VXPtcB7ITybTOh/ZJLLwnl8lGdwCV5F2Nmpsz gxBvWAj4wPkkurSSLVLZjOlL2YQHSNxR/m9N5wSTEE= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201106/1 X-Sequence-Number: 43934 On 05/30/2011 08:08 PM, Jarrod Chesney wrote: > My database uses joined table inheritance and my server version is 9.0 > I have about 120,000 records in the table that everything else inherits from, if i truncate-cascaded this table it happens almost instantly. If i run 30,000 prepared "DELETE FROM xxx WHERE "ID" = ?" commands it takes close to 10 minutes. > > My foreign keys to the base table are all set with "ON DELETE CASCADE". You may also want to make them DEFERRABLE and then use "SET CONSTRAINTS ALL DEFERRABLE" so that the constraint checking all happens at one time. This will cause more memory to be used, but all the constraint related work will happen in a batch. You mentioned inheritance. That can cause some unexpected problems sometimes. You might want to do: EXPLAIN DELETE FROM ... To see how this is executing. EXPLAIN works fine on DELETE statements, too, and it may highlight something strange about how the deletion is happening. If you can, use EXPLAIN ANALYZE, but note that this will actually execute the statement--the deletion will happen, it's not just a test. There may be a problem with the query plan for the deletion that's actually causing the issue here, such as missing the right indexes. If you have trouble reading it, http://explain.depesz.com/ is a good web resources to help break down where the time is going. -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us "PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books