Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id D13AA9FA5F9 for ; Sun, 29 Jul 2007 01:51:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 95150-06 for ; Sun, 29 Jul 2007 01:51:42 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.187]) by postgresql.org (Postfix) with ESMTP id 4C5959FA5F5 for ; Sun, 29 Jul 2007 01:51:43 -0300 (ADT) Received: by rv-out-0910.google.com with SMTP id f1so216449rvb for ; Sat, 28 Jul 2007 21:51:42 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=X9c1UOP0zYgWOocmcu5I3X+Glci61YPP046ybvdYkzXDgPP5KJ460k+zGXU5zdJKq6PKmt0H1Ki0Pl1P5/u9Os4ijlsrciDlzQmzgQwUGfO5OsqyHsE1HmOViJOtt2TkEO621n8ltG435Q8u5g5lQiAqoA2PU07gjgpEI5h0JG4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=laWxII72v2Xs0mlf4Cn5bYwY5CEnpeOSmpwMaFeJ1yc+SvfmlDaKAFWBShf1iD/pEu1ZZZTHpDxmBhm0GdtyzH1BNcNgP5eFpwk6RQAtChvFsop8OxLrSVG+eQP9rhGJLPkxW/rljNV6UgnttTpnGgy3M13cJhV97bft+2tzBDQ= Received: by 10.141.88.3 with SMTP id q3mr1411973rvl.1185684701979; Sat, 28 Jul 2007 21:51:41 -0700 (PDT) Received: by 10.141.162.12 with HTTP; Sat, 28 Jul 2007 21:51:41 -0700 (PDT) Message-ID: Date: Sat, 28 Jul 2007 23:51:41 -0500 From: "Scott Marlowe" To: "Bruno Rodrigues Siqueira" Subject: Re: select on 1milion register = 6s Cc: pgsql-performance@postgresql.org In-Reply-To: <002001c7d153$944f3c60$e900a8c0@brunolaptop> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46ABA01E.8000802@emolecules.com> <002001c7d153$944f3c60$e900a8c0@brunolaptop> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/410 X-Sequence-Number: 26094 On 7/28/07, Bruno Rodrigues Siqueira wrote: > > Ok. > QUERY PLAN > Sort (cost=11449.37..11449.40 rows=119 width=8) (actual > time=14431.537..14431.538 rows=2 loops=1) > Sort Key: to_char(data_encerramento, 'yyyy-mm'::text) > -> HashAggregate (cost=11448.79..11448.96 rows=119 width=8) (actual > time=14431.521..14431.523 rows=2 loops=1) > -> Index Scan using detalhamento_bas_idx3003 on detalhamento_bas > (cost=0.00..11442.95 rows=11679 width=8) (actual time=0.135..12719.155 > rows=2335819 loops=1) See the row mismatch there? It expects about 11k rows, gets back 2.3 million. That's a pretty big misestimate. Have you run analyze recently on this table? Is there a reason you're doing this: to_char( data_encerramento ,'yyyy-mm') between '2006-12' and '2007-01' when you should be able to just do: data_encerramento between '2006-12-01' and '2007-01-31' ? that should be able to use good estimates from analyze. My guess is the planner is making a bad guess because of the way you're handling the dates. > SERVER > DELL PowerEdge 2950 > XEON Quad-Core 3.0Ghz > 4Gb RAM > Linux CentOS 5.0 64-bits > Postgres 8.1.4 > Postgresql.conf > # - Memory - > > shared_buffers = 50000 # min 16 or max_connections*2, 8KB 400 Meg is kind of low for a server with 4 G ram. 25% is more reasonable (i.e. 125000 buffers) > work_mem = 3145728 # min 64, size in KB > maintenance_work_mem = 4194304 # min 1024, size in KB Whoa nellie! thats ~ 3 Gig of work mem, and 4 gig of maintenance work mem. In a machine with 4 gig ram, that's a recipe for disaster. Something more reasonable would be 128000 (~125Meg) for each since you've limited your machine to 10 connections you should be ok. setting work_mem too high can run your machine out of memory and into a swap storm that will kill performance. > fsync = off # turns forced synchronization on or > off So, the data in this database isn't important? Cause that's what fsync = off says to me. Better to buy yourself a nice battery backed caching RAID controller than turn off fsync. > effective_cache_size = 41943040 # typically 8KB each And you're machine has 343,604,830,208 bytes of memory available for caching? Seems a little high to me. > random_page_cost = 1 # units are one sequential page > fetch Seldom if ever is it a good idea to bonk the planner on the head with random_page_cost=1. setting it to 1.2 ot 1.4 is low enough, but 1.4 to 2.0 is more realistic. > stats_start_collector = off > #stats_command_string = off > #stats_block_level = off > #stats_row_level = off > #stats_reset_on_server_start = off I think you need stats_row_level on for autovacuum, but I'm not 100% sure. Let us know what happens after fixing these settings and running analyze and running explain analyze, with possible changes to the query.