Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id BBFC09FA248 for ; Wed, 13 Dec 2006 19:44:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 21974-07 for ; Wed, 13 Dec 2006 19:44:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C2D599FA0B7 for ; Wed, 13 Dec 2006 19:44:49 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id kBDNilWB013155; Wed, 13 Dec 2006 18:44:47 -0500 (EST) To: "Steven Flatt" cc: pgsql-performance@postgresql.org Subject: Re: Insertion to temp table deteriorating over time In-reply-to: <357fa7590612131517q375fc0by50cb4257bcce7a94@mail.gmail.com> References: <357fa7590612130844q58ef3ca5q31e164f9b006e0fc@mail.gmail.com> <9315.1166030958@sss.pgh.pa.us> <357fa7590612131517q375fc0by50cb4257bcce7a94@mail.gmail.com> Comments: In-reply-to "Steven Flatt" message dated "Wed, 13 Dec 2006 18:17:41 -0500" Date: Wed, 13 Dec 2006 18:44:47 -0500 Message-ID: <13154.1166053487@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/352 X-Sequence-Number: 22408 "Steven Flatt" writes: > Having said that, what kinds of things should I be looking for that could > deteriorate/bloat over time? Ordinarily the culprit might be infrequent > vacuuming or analyzing, but that wouldn't be corrected by a restart of > Postgres. In our case, restarting Postgres gives us a huge performance > improvement (for a short while, anyways). > By the way, we are using PG 7.4.6 on FreeBSD 5.30.0170. The temp table has > 15 columns: a timestamp, a double, and the rest integers. It has no > indexes. Hm, *are* you vacuuming only infrequently? In particular, what is your maintenance policy for pg_class? Some experimentation with TRUNCATE and VACUUM VERBOSE shows that in 7.4, a TRUNCATE of a temp table with no indexes and no toast table generates three dead row versions in pg_class. (I'm surprised that it's as many as three, but in any case the TRUNCATE would certainly have to do one update of the table's pg_class entry and thereby generate one dead row version.) If you're being sloppy about vacuuming pg_class, then over time the repeated-truncate pattern would build up a huge number of dead rows in pg_class, *all with the same OID*. It's unsurprising that this would create some slowness in looking up the temp table's pg_class entry. If this theory is correct, the reason that starting a fresh backend makes it fast again is that the new backend creates a whole new temp table with a new OID assigned, and so the adjacent litter in pg_class doesn't matter anymore (or not so much anyway). Solution would be to institute regular vacuuming of the system catalogs... regards, tom lane