Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 8108C9FA61D for ; Wed, 11 Jul 2007 18:11:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 04018-05 for ; Wed, 11 Jul 2007 18:10:46 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smtp.vodafone.nl (smtp-out.vizzavi.nl [195.232.199.126]) by postgresql.org (Postfix) with ESMTP id ABB879FA4A0 for ; Wed, 11 Jul 2007 18:10:57 -0300 (ADT) Received: from conversion-daemon.vfnlw44s.vfnl.dc-ratingen.de by vfnlw44s.vfnl.dc-ratingen.de (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) id <0JL100A016O94700@vfnlw44s.vfnl.dc-ratingen.de> (original mail from postgres@microbizz.nl) for pgsql-performance@postgresql.org; Wed, 11 Jul 2007 22:10:47 +0200 (MEST) Received: from [212.56.242.41] by vfnlw44s.vfnl.dc-ratingen.de (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JL100FGF6PQEY10@vfnlw44s.vfnl.dc-ratingen.de> for pgsql-performance@postgresql.org; Wed, 11 Jul 2007 22:10:46 +0200 (MEST) Date: Wed, 11 Jul 2007 22:10:49 +0200 From: Adriaan van Os Subject: TRUNCATE TABLE To: pgsql-performance@postgresql.org Message-id: <46953949.3030201@microbizz.nl> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7BIT User-Agent: Thunderbird 1.5.0.4 (Macintosh/20060516) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/125 X-Sequence-Number: 25809 Recently, I have been doing extensive profiling of a version 8.1.4 Postgres DB with about 175 tables and 5 GB of data (the server running on Fedora Linux and the clients on Windows XP). Surprisingly, one of the bottlenecks is TRUNCATE TABLE and that command is really slow as compared to other operations. For example, we have operations like: TRUNCATE TABLE my_temporary_table COPY my_temporary_table ... FROM STDIN BINARY do_something where do_something is using the data in my_temporary_table to do something like a JOIN or a mass UPDATE or whatever. Now, it turns out that typically most time is lost in TRUNCATE TABLE, in fact it spoils the performance of most operations on the DB ! I read in a mailing list archive that TRUNCATE TABLE is slow since it was made transaction-safe somewhere in version 7, but for operations on a temporary table (with data coming from the outside world) that is irrelevant, at least for my application, in casu, a middleware software package. So, my questions are 1. Why is TRUNCATE TABLE so slow (even if transaction-safe) 2. Is there is way to dig up in the source code somewhere a quick-and-dirty TRUNCATE TABLE alternative for operations on temporary tables that need not be transaction-safe (because the middleware itself can easily restore anything that goes wrong there). I noticed, by the way, that removing records in general is painfully slow, but I didn't do a detailed analysis of that issue yet. As an alternative to TRUNCATE TABLE I tried to CREATE and DROP a table, but that wasn't any faster. Sincerely, Adriaan van Os