Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DFD549FA47A for ; Sun, 22 Jul 2007 15:35:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 67902-03 for ; Sun, 22 Jul 2007 15:35:14 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.236]) by postgresql.org (Postfix) with ESMTP id E3CE29FA479 for ; Sun, 22 Jul 2007 15:35:12 -0300 (ADT) Received: by wx-out-0506.google.com with SMTP id h29so1234566wxd for ; Sun, 22 Jul 2007 11:35:12 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:subject:from:reply-to:to:in-reply-to:references:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding; b=b2p7RugF8N8fopieJKWXCU0cjC+zayrNlwSQDH6jwBw0wGILAHZhyzh1OF5BYftxAwfiTJqqsN05e13I6JrRdEpWJ7NdQ0AQIjRY0eNviQJVY/C6z2cU5HH+IiU2yUCf24+dcLa2VedAqHbwezwlvP9n01WE/hoZ6jcw0+cNS6Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:subject:from:reply-to:to:in-reply-to:references:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding; b=YpGLDsnxs5vrz40vKojvcsNZjQJiBknHfd6KkfBv5CSWk0gADTt3xhxA3xuPii61CpO0ohuZpeg45FJJ5teS4KY7Ra/Yg+p/416TDjxczsFu45p4btmyPuphNbf5y+Sy4+3li70prWOPRGpFgbQ20PSLguq5xZZzeArjXm8+k8Q= Received: by 10.90.52.18 with SMTP id z18mr1396104agz.1185129312064; Sun, 22 Jul 2007 11:35:12 -0700 (PDT) Received: from ?192.168.3.170? ( [68.79.189.145]) by mx.google.com with ESMTPS id 7sm6480265aga.2007.07.22.11.35.10 (version=SSLv3 cipher=RC4-MD5); Sun, 22 Jul 2007 11:35:10 -0700 (PDT) Subject: Re: Simple select hangs while CPU close to 100% From: Adam Tauno Williams Reply-To: adamtaunowilliams@gmail.com To: pgsql-performance@postgresql.org In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Date: Sun, 22 Jul 2007 14:32:45 -0400 Message-Id: <1185129165.4159.1.camel@aleph.whitemice.org> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/286 X-Sequence-Number: 25970 > I’m having this very disturbing problem. I got a table with about > 100,000 rows in it. Our software deletes the majority of these rows > and then bulk loads another 100,000 rows into the same table. All this > is happening within a single transaction. I then perform a simple > “select count(*) from …” statement that never returns. In the mean COUNT(*) is always slow; but either way if the process is deleting and then adding records, can't you just keep track of how may records you loaded [aka count++] rather than turning around and asking the database before any statistics have had a chance to be updated. > time, the backend Postgres process is taking close to 100% of the > CPU. The hang-up does not always happen on the same statement but > eventually it happens 2 out of 3 times. If I dump and then restore the > schema where this table resides the problem is gone until the next > time we run through the whole process of deleting, loading and > querying the table. > There is no other activity in the database. All requested locks are > granted.