Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 73D811EB83EA for ; Thu, 23 Feb 2012 15:04:51 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S0dyC-0004Xg-Cn for pgsql-performance@postgresql.org; Thu, 23 Feb 2012 19:04:50 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q1NJ4YSe003807; Thu, 23 Feb 2012 14:04:34 -0500 (EST) To: "Reuven M. Lerner" cc: pgsql-performance@postgresql.org Subject: Re: Very long deletion time on a 200 GB database In-reply-to: <4F45FB55.1020600@lerner.co.il> References: <4F45FB55.1020600@lerner.co.il> Comments: In-reply-to "Reuven M. Lerner" message dated "Thu, 23 Feb 2012 10:39:49 +0200" Date: Thu, 23 Feb 2012 14:04:34 -0500 Message-ID: <3806.1330023874@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/179 X-Sequence-Number: 46351 I just reread the original post and noted this: "Reuven M. Lerner" writes: > (1) I tried to write this as a join, rather than a subselect. But B has > an oid column that points to large objects, and on which we have a rule > that removes the associated large object when a row in B is removed. A rule? Really? That's probably bad enough in itself, but when you write an overcomplicated join delete query, I bet the resulting plan is spectacularly bad. Have you looked at the EXPLAIN output for this? I'd strongly recommend getting rid of the rule in favor of a trigger. Also, as already noted, the extra join inside the IN sub-select is probably hurting far more than it helps. > (3) There are some foreign-key constraints on the B table. If those are FK references *to* the B table, make sure the other end (the referencing column) is indexed. Postgres doesn't require an index on a referencing column, but deletes in the referenced table will suck if you haven't got one. I don't think any of the fancy stuff being discussed in the thread is worth worrying about until you've got these basic issues dealt with. regards, tom lane