Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 779869F9F46 for ; Wed, 13 Dec 2006 12:44:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 99011-02-4 for ; Wed, 13 Dec 2006 12:44:21 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.227]) by postgresql.org (Postfix) with ESMTP id 7E3329FA248 for ; Wed, 13 Dec 2006 12:44:20 -0400 (AST) Received: by wx-out-0506.google.com with SMTP id i28so216574wxd for ; Wed, 13 Dec 2006 08:44:19 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=eY5ZUjThbhQlXQzciDhr6JYmRsxzIHbfo2saQ8YgN+LSGFxntt/iw074AF0+9Ri3+K92OjIbKM+ihsHc+nfng3sw29P1vBzH06rMgeBUHv2KLvln3ZPgVu79BAfXfyRT382QhHqZ0ZMqLCK53Piey95lgoM1y/l3NRBLI3gwQMs= Received: by 10.70.80.14 with SMTP id d14mr1891900wxb.1166028259625; Wed, 13 Dec 2006 08:44:19 -0800 (PST) Received: by 10.70.108.15 with HTTP; Wed, 13 Dec 2006 08:44:19 -0800 (PST) Message-ID: <357fa7590612130844q58ef3ca5q31e164f9b006e0fc@mail.gmail.com> Date: Wed, 13 Dec 2006 11:44:19 -0500 From: "Steven Flatt" To: pgsql-performance@postgresql.org Subject: Insertion to temp table deteriorating over time MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_140820_24849456.1166028259590" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/324 X-Sequence-Number: 22380 ------=_Part_140820_24849456.1166028259590 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, Our application is using Postgres 7.4 and I'd like to understand the root cause of this problem: To speed up overall insert time, our application will write thousands of rows, one by one, into a temp table (same structure as a permanent table), then do a bulk insert from the temp table to the permanent table. After this bulk insert is done, the temp table is truncated and the process is repeated. We do this because Postgres can do many individual inserts to a temp table much faster than to a permanent table. The problem we are seeing is that over time, the cost of a single insert to the temp table seems to grow. After a restart of postgres, a single insert to the temp table takes about 3ms. Over a few days, this grows to about 60ms per insert. Restarting postgres drops this insert time back to 3ms, supposedly because the temp table is re-created. Our workaround right now is to restart the database every few days, but we don't like this solution much. Any idea where the bloat is happening? I believe that if we were dropping and re-creating the temp table over and over, that could result in pg_class bloat (among other catalog tables), but what is going wrong if we use the same table over and over and truncate it? Thanks, Steve ------=_Part_140820_24849456.1166028259590 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hi,
 
Our application is using Postgres 7.4 and I'd like to understand the root cause of this problem:
 
To speed up overall insert time, our application will write thousands of rows, one by one, into a temp table (same structure as a permanent table), then do a bulk insert from the temp table to the permanent table.  After this bulk insert is done, the temp table is truncated and the process is repeated.  We do this because Postgres can do many individual inserts to a temp table much faster than to a permanent table.
 
The problem we are seeing is that over time, the cost of a single insert to the temp table seems to grow.  After a restart of postgres, a single insert to the temp table takes about 3ms.  Over a few days, this grows to about 60ms per insert.  Restarting postgres drops this insert time back to 3ms, supposedly because the temp table is re-created.  Our workaround right now is to restart the database every few days, but we don't like this solution much.
 
Any idea where the bloat is happening?  I believe that if we were dropping and re-creating the temp table over and over, that could result in pg_class bloat (among other catalog tables), but what is going wrong if we use the same table over and over and truncate it?
 
Thanks,
Steve
------=_Part_140820_24849456.1166028259590--