pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shaun Thomas <sthomas@peak6.com>
To: felix <crucialfelix@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Really really slow select count(*)
Date: Tue, 8 Feb 2011 08:23:02 -0600
Message-ID: <4D5151C6.7040109@peak6.com> (raw)
In-Reply-To: <AANLkTiknh-snZvy4_PzS9CgVfNCH3RTS+V=COWVOnTNo@mail.gmail.com>
References: <AANLkTinAJcm5A+i1O_R87aiYyu8N2OWgoaL9RfR=tUR9@mail.gmail.com>
	<4D4C138C.7010304@2ndquadrant.com>
	<4D4C1555.40209@peak6.com>
	<AANLkTikrS5JkJDMjAXpcRWRnuLbX+MHB=CWb_mFa9qb-@mail.gmail.com>
	<4D4C2AC3.5020804@peak6.com>
	<AANLkTin8ndBSU9ZJ2uAdnvYQ7oLBg2S04bqAXn-s5qv+@mail.gmail.com>
	<AANLkTim+aLaihKbNSsiiL4exgtCeRqCh_50j48jHFDQm@mail.gmail.com>
	<AANLkTimnFc-hKG+PFEfwBPLAoK6q9kx=nc_4Fr++C_QB@mail.gmail.com>
	<D247E79EFD801E40A9449A9724F6295B0474BBF807@spswchi6mail1.peak6.net>
	<AANLkTiknh-snZvy4_PzS9CgVfNCH3RTS+V=COWVOnTNo@mail.gmail.com>

On 02/07/2011 09:17 PM, felix wrote:

> Well.... it said "Failed to shutdown ..............."  and then
> returned control. and then proceeded to run for about an hour. I'm
> not sure how graceful that is.

Ah, but that was just the control script that sends the database the 
command to shut down. The 'graceful' part, is that the database is being 
nice to everyone trying to do things with the data inside.

The control script has a timeout. So it'll send the command, wait a few 
seconds to see if the database responds, and then gives up. At that 
point, you can use a fast shutdown to tell the database not to be so 
nice, and it'll force disconnect all users and shut down as quickly as 
possible while maintaining data integrity.

The easiest way to see this in action is to take a look at the postgres 
log files. In most default installs, this is in /your/pg/dir/pg_log and 
the files follow a postgresql-YYYY-MM-DD_HHMMSS.log format and generally 
auto-rotate. If not, set redirect_stderr to on, and make sure 
log_directory and log_filename are both set. Those are in your 
postgresql.conf, by the way. :)

> I've only been using postgres since we migrated in May

Aha. Yeah... relatively new installs tend to have the worst growing 
pains. Once you shake this stuff out, you'll be much better off.

> its only conjecture that the issue is file space bloat or free map
> problems.  those are overall issues that I will get to as soon as I can.
> but this is table specific.

With 300k rows, count(*) isn't a good test, really. That's just on the 
edge of big-enough that it could be > 1-second to fetch from the disk 
controller, even if the table is fully vacuumed. And in your case, that 
table really will likely come from the disk controller, as your 
shared_buffers are set way too low. The default settings are not going 
to cut it for a database of your size, with the volume you say it's getting.

But you need to put in those kernel parameters I suggested. And I know 
this sucks, but you also have to raise your shared_buffers and possibly 
your work_mem and then restart the DB. But this time, pg_ctl to invoke a 
fast stop, and then use the init script in /etc/init.d to restart it.

> I am not a DBA,

You are now. :) You're administering a database, either as part of your 
job description, or because you have no choice because your company 
doesn't have an official DBA. Either way, you'll need to know this 
stuff. Which is why we're helping out.

-- 
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas@peak6.com

______________________________________________

See  http://www.peak6.com/email_disclaimer.php
for terms and conditions related to this email



view thread (66+ messages)  latest in thread

Message-ID: <4D5151C6.7040109@peak6.com>
Permalink:  ../4D5151C6.7040109@peak6.com/
Also on:    postgresql.org/message-id/4D5151C6.7040109@peak6.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: sthomas@peak6.com, crucialfelix@gmail.com
  Subject: Re: Really really slow select count(*)
  In-Reply-To: <4D5151C6.7040109@peak6.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox