Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 12B571337C0F for ; Tue, 26 Apr 2011 20:23:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 59667-07 for ; Tue, 26 Apr 2011 23:23:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id 178B11337BFA for ; Tue, 26 Apr 2011 20:23:41 -0300 (ADT) Received: by vws1 with SMTP id 1so863333vws.19 for ; Tue, 26 Apr 2011 16:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=osu7UOCiby77t/+EW2UxYZSABbXGC5QTxRaQpC6m0KI=; b=lhw3es/tL64ak+som9EuUG8UAush5t9VYEoyiT7aPX795YM9Qcubdo3+kdBV8ahQ7y 0u2hv7M1ewnvZ5CQj4e8t6yJyGG37t/n09bEOkvG61Zzd/fP+yE0NZosPDUWNBqnbCnV 3LXsJTNE5LS9pQMXkSt0J5wZJoFE010OSnwm4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=HCdS084PeqQZSLYwr2WcoZtbjXQ3zS+NrrIZ2crLgARBC5Ikgw+CkHYaqoBMlj+tgW lfr+gxhccLTmVXJ3+5B6cKDL9EuAmkD6vxxOu/kP+IhSucFUGfnrHpKgrG5fiR8Sc62s YKGdeXhcCGJ+pFsx42i/UBZjElbvfHa4tl5UA= MIME-Version: 1.0 Received: by 10.52.112.131 with SMTP id iq3mr1978333vdb.1.1303860222198; Tue, 26 Apr 2011 16:23:42 -0700 (PDT) Received: by 10.52.164.234 with HTTP; Tue, 26 Apr 2011 16:23:42 -0700 (PDT) In-Reply-To: <4DB6F4BB020000250003CEB9@gw.wicourts.gov> References: <4DB6F4BB020000250003CEB9@gw.wicourts.gov> Date: Wed, 27 Apr 2011 07:23:42 +0800 Message-ID: Subject: Re: reducing random_page_cost from 4 to 2 to force index scan From: Sok Ann Yap To: Kevin Grittner Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201104/387 X-Sequence-Number: 43449 On Wed, Apr 27, 2011 at 5:37 AM, Kevin Grittner wrote: > Sok Ann Yap wrote: > >> So, index scan wins by a very small margin over sequential scan >> after the tuning. I am a bit puzzled because index scan is more >> than 3000 times faster in this case, but the estimated costs are >> about the same. Did I do something wrong? > > Tuning is generally needed to get best performance from PostgreSQL. > Needing to reduce random_page_cost is not unusual in situations > where a good portion of the active data is in cache (between > shared_buffers and the OS cache). =C2=A0Please show us your overall > configuration and give a description of the hardware (how many of > what kind of cores, how much RAM, what sort of storage system). =C2=A0The > configuration part can be obtained by running the query on this page > and pasting the result into your next post: > > http://wiki.postgresql.org/wiki/Server_Configuration > > There are probably some other configuration adjustments you could do > to ensure that good plans are chosen. > > -Kevin > Here's the configuration (this is just a low end laptop): name | current_setting ----------------------------+----------------------------------------------= ---------------------------------------------------------------------------= ------ version | PostgreSQL 9.0.4 on x86_64-pc-linux-gnu, compiled by GCC x86_64-pc-linux-gnu-gcc (Gentoo 4.5.2 p1.0, pie-0.4.5) 4.5.2, 64-bit checkpoint_segments | 16 default_statistics_target | 10000 effective_cache_size | 512MB lc_collate | en_US.UTF-8 lc_ctype | en_US.UTF-8 listen_addresses | * log_destination | syslog log_min_duration_statement | 0 maintenance_work_mem | 256MB max_connections | 100 max_stack_depth | 2MB port | 5432 random_page_cost | 4 server_encoding | UTF8 shared_buffers | 256MB silent_mode | on TimeZone | Asia/Kuala_Lumpur wal_buffers | 1MB work_mem | 32MB (20 rows) The thing is, the query I posted was fairly simple (I think), and PostgreSQL should be able to choose the 3000+ times faster index scan with the default random_page_cost of 4. If I need to reduce it to 2 when using a 5.4k rpm slow disk, what is random_page_cost =3D 4 good for? (Sorry for the double message, I forgot to CC the list in the first one)