X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4866A9DC9B6 for ; Mon, 19 Dec 2005 06:39:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09005-02 for ; Mon, 19 Dec 2005 06:39:35 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail5.dslextreme.com (mail5.dslextreme.com [66.51.199.81]) by postgresql.org (Postfix) with SMTP id 4ABE59DC98E for ; Mon, 19 Dec 2005 06:39:30 -0400 (AST) Received: (qmail 10477 invoked from network); 19 Dec 2005 10:38:50 -0000 Received: from unknown (HELO [10.1.1.1]) (mitchskin@66.245.216.230) by mail5.dslextreme.com with SMTP; Mon, 19 Dec 2005 02:38:50 -0800 Subject: Re: make bulk deletes faster? From: Mitch Skinner To: James Klo Cc: pgsql-performance@postgresql.org In-Reply-To: References: Content-Type: text/plain Date: Mon, 19 Dec 2005 02:39:31 -0800 Message-Id: <1134988771.3208.81.camel@firebolt> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.04 required=5 tests=[AWL=0.040] X-Spam-Score: 0.04 X-Spam-Level: X-Archive-Number: 200512/452 X-Sequence-Number: 16273 On Sat, 2005-12-17 at 21:10 -0800, James Klo wrote: > I need to routinely move data from the timeblock table to an archive > table with the same schema named timeblock_archive. I really need this > to happen as quickly as possible, as the archive operation appears to > really tax the db server... Have you considered partitioning? http://www.postgresql.org/docs/8.1/interactive/ddl-partitioning.html If you can partition your timeblock table so that you archive an entire partition at a time, then you can delete the archived rows by just dropping (or truncating) that partition. AFAIK there's no way to "re-parent" a partition (e.g., from the timeblock table to the timeblock_archive table). If your app is particularly cooperative you might be able to use partitioning to avoid moving data around entirely. If table accesses are always qualified by something you can use as a partitioning key, then partitioning can give you the speed benefits of a small table without the effort of keeping it cleared out. Another good read, if you haven't yet, is http://powerpostgresql.com/Downloads/annotated_conf_80.html especially the "Memory", "Checkpoints", and maybe "WAL options" sections. If you're doing large deletes then you may need to increase your free space map settings--if a VACUUM VERBOSE finishes by saying that you need more FSM pages, then the table may have gotten bloated over time (which can be fixed with a configuration change and a VACUUM FULL, though this will lock everything else out of the table while it's running). Mitch