Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id AE2D8174E985 for ; Fri, 24 Feb 2012 02:40:13 -0400 (AST) Received: from server.lerner.co.il ([69.55.231.200] helo=lerner.co.il) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S0op8-0005Qk-Jc for pgsql-performance@postgresql.org; Fri, 24 Feb 2012 06:40:11 +0000 Received: by lerner.co.il (Postfix, from userid 1003) id 81EFE5D6320; Fri, 24 Feb 2012 08:39:56 +0200 (IST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on lerner.co.il X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable version=3.3.2 Received: from MacBookPro.local (bzq-84-108-219-125.cablep.bezeqint.net [84.108.219.125]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: reuven) by lerner.co.il (Postfix) with ESMTPSA id B5A7F5D615A; Fri, 24 Feb 2012 08:39:50 +0200 (IST) Message-ID: <4F4730B4.2050602@lerner.co.il> Date: Fri, 24 Feb 2012 08:39:48 +0200 From: "Reuven M. Lerner" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: Glyn Astill CC: "pgsql-performance@postgresql.org" Subject: Re: Very long deletion time on a 200 GB database References: <4F45FB55.1020600@lerner.co.il> <1329990620.15378.YahooMailNeo@web171403.mail.ir2.yahoo.com> In-Reply-To: <1329990620.15378.YahooMailNeo@web171403.mail.ir2.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/192 X-Sequence-Number: 46364 Hi, everyone. So it turns out that we're not using 25 GB of virtual memory. (That's what I had been shown yesterday, and it was a bit surprising, to say the least...) A few statistics that I managed to get from the Windows developers/system administrators: - The machine has a total of 3.5 GB of RAM - shared_buffers was set to 256 MB (yes, MB!) - Virtual memory usage by our process is 3 MB (yes, MB) - CPU is virtually idle when running the deletes, using about 1% of CPU - No other processes are accessing the database when we're running the maintenance; there are a total of three server processes, but two are idle. (I was a bit surprised, to say the least, by the low number on shared_buffers, given that I believe it's one of the first things I told them to increase about 18 months ago.) As for Tom's point about rules, I know that rules are bad, and I'm not sure why the system is using a rule rather than a trigger. I'll see if I can change that to a trigger, but I have very indirect control over the machines, and every change requires (believe it or not) writing a .NET program that runs my changes, rather than just a textual script that deploys them. The only foreign keys are from the B table (i.e., the table whose records I want to remove) to other tables. There are no REFERENCES pointing to the B table. That said, I hadn't realized that primary keys and indexes can also delay the DELETE. For the latest round of testing, I quadrupled shared_buffers to 1 GB, turned off hash joins (as suggested by someone), and also simplified the query (based on everyone's suggestions). In the tests on my own computer (with a somewhat random 1 GB snapshot of the 200 GB database), the simplified query was indeed much faster, so I'm optimistic. Several people suggested that chunking the deletes might indeed help, which makes me feel a bit better. Unfortunately, given the time that it takes to run the queries, it's hard to figure out the right chunk size. Whoever suggested doing it in time slices had an interesting idea, but I'm not sure if it'll be implementable given our constraints. Thanks again to everyone for your help. I'll let you know what happens... Reuven