X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id B1B9E9FB2F6 for ; Mon, 10 Jul 2006 13:04:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 96065-03 for ; Mon, 10 Jul 2006 13:04:19 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 2197C9FB2E2 for ; Mon, 10 Jul 2006 13:04:18 -0300 (ADT) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Mon, 10 Jul 2006 16:04:18 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 10 Jul 2006 11:04:18 -0500 Subject: Re: High CPU Usage - PostgreSQL 7.3 From: Scott Marlowe To: Neil Hepworth Cc: pgsql-performance@postgresql.org In-Reply-To: <5a6f767a0607091752y5018f9eaw474dc5cf7de3c4c3@mail.gmail.com> References: <5a6f767a0607091752y5018f9eaw474dc5cf7de3c4c3@mail.gmail.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1152547458.6540.6.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Mon, 10 Jul 2006 11:04:18 -0500 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/91 X-Sequence-Number: 19951 On Sun, 2006-07-09 at 19:52, Neil Hepworth wrote: > Hi, > > I am running PostgreSQL 7.3 on a Linux box (RHEL 2.1 - Xeon 2.8GHz > with 1GB of RAM) and seeing very high CPU usage (normally over 90%) > when I am running the following queries, and the queries take a long > time to return; over an hour! > > CREATE TEMPORARY TABLE fttemp1600384653 AS SELECT * FROM ftoneway LIMIT 0; > > INSERT INTO fttemp1600384653 SELECT epId, TO_TIMESTAMP(start, > 'YYYY-MM-DD HH24:00:00.0')::timestamp AS start, 60 AS consolidation, > SUM(cnt) AS cnt FROM ftone WHERE consolidation = 0 AND start < > TO_TIMESTAMP('2006-06-27 18:43:27.391103+1000', 'YYYY-MM-DD > HH24:00:00.0')::timestamp; I don't need to see an explain analyze to make a guess here... start < TO_TIMESTAMP('2006-06-27 18:43:27.391103+1000', 'YYYY-MM-DD HH24:00:00.0')::timestamp is gonna be a problem because while you and I know that to_timestamp... is gonna be a constant, pg 7.3 doesn't. I've run into this before. Just run a query ahead of time with a simple: select TO_TIMESTAMP('2006-06-27 18:43:27.391103+1000', 'YYYY-MM-DD HH24:00:00.0')::timestamp as starttime and then pull that out and stick it into your query. do the same for any other parts of the query like that. That's assuming the issue here is that you're getting seq scans cause of that part of the query.