Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id F41EA1337B99 for ; Thu, 10 Feb 2011 14:00:43 -0400 (AST) 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 46681-03 for ; Thu, 10 Feb 2011 18:00:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f174.google.com (mail-gx0-f174.google.com [209.85.161.174]) by mail.postgresql.org (Postfix) with ESMTP id 54E9F1337B7E for ; Thu, 10 Feb 2011 14:00:36 -0400 (AST) Received: by gxk9 with SMTP id 9so712383gxk.19 for ; Thu, 10 Feb 2011 10:00:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:from:date:message-id:subject:to :content-type; bh=XgrfaXpWe9/mH3dD3fMArXPrsUHI5onWGTzXmRWoo8Y=; b=nkBqzPPleHUmJvQ/V7qfce8hsWrwQ9RkiSVOo4EOJMXyQ/v2Y1Gb5Uhxh71sk2H1TB tLD6quLftUL5l0gMWSWaZgLbJCSdE07BmtN+WJLkSKH0tAHaZlbp3n7pRAF+KT2q6Kel mfKbXhJwFtFDi8Puvtpw16has5I174f/lxBkw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=h3XK8KvDavEyy6VnjfpDUADpgYPPZtFTC7DKoKNs4DIHWb8jfAme2exJR0Q+3vKPNk BPxpks2CScmxfdqtIOQ6QidqQuT4Qn0JVrvD2a797ddHQ2AXHUd+jyGWi9MxTJH1OyQk UtBH3ccAffEcXgU3E8p7quQZUXKHmmsVY8+oQ= Received: by 10.236.108.131 with SMTP id q3mr6688747yhg.85.1297360723981; Thu, 10 Feb 2011 09:58:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.105.236 with HTTP; Thu, 10 Feb 2011 09:57:23 -0800 (PST) From: Josh Date: Thu, 10 Feb 2011 11:57:23 -0600 Message-ID: Subject: DELETE FROM takes forever To: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.242 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_BL_SPAMCOP_NET=1.347, RCVD_IN_DNSWL_LOW=-0.7, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201102/45 X-Sequence-Number: 35121 Hi I'm trying to do a DELETE FROM on my large table (about 800 million rows) based on the contents of another, moderately large table (about 110 million rows). The command I'm using is: DELETE FROM records WHERE id NOT IN (SELECT id FROM unique_records); This process ran for about two weeks before I decided to stop it -- it was dragging down the DB server. I can understand long-running processes, but two weeks seems a bit much even for a big table. Is this the best way to approach the problem? Is there a better way? Some background: The server is version 8.3, running nothing but Pg. The 'records' table has 'id' as its primary key, and one other index on another column. The table is referenced by just about every other table in my DB (about 15 other tables) via foreign key constraints, which I don't want to break (which is why I'm not just recreating the table rather than deleting rows). Most of the dependent tables have ON DELETE CASCADE. The 'unique_records' table is a temp table I got via something like: SELECT DISTINCT (other_column) id INTO unique_records FROM records Thanks very much! Josh Leder