Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 2D37C1259185 for ; Fri, 27 Jan 2012 14:05:27 -0400 (AST) Received: from exprod7og102.obsmtp.com ([64.18.2.157]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RqqAu-00084w-7o for pgsql-performance@postgresql.org; Fri, 27 Jan 2012 18:05:26 +0000 Received: from mail-lpp01m010-f48.google.com ([209.85.215.48]) (using TLSv1) by exprod7ob102.postini.com ([64.18.6.12]) with SMTP ID DSNKTyLnVYv2B5RSzNmHSCF0g4qfeAVOX00U@postini.com; Fri, 27 Jan 2012 10:05:23 PST Received: by lagz14 with SMTP id z14so1781827lag.21 for ; Fri, 27 Jan 2012 10:05:08 -0800 (PST) Received: by 10.152.114.68 with SMTP id je4mr4361739lab.35.1327687508347; Fri, 27 Jan 2012 10:05:08 -0800 (PST) Received: from [192.168.1.102] (dsl-hkibrasgw2-ff6cc300-200.dhcp.inet.fi. [88.195.108.200]) by mx.google.com with ESMTPS id mc3sm6459571lab.12.2012.01.27.10.05.07 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jan 2012 10:05:07 -0800 (PST) Message-ID: <4F22E752.5000506@enterprisedb.com> Date: Fri, 27 Jan 2012 20:05:06 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20120104 Icedove/8.0 MIME-Version: 1.0 To: Jon Nelson CC: pgsql-performance@postgresql.org Subject: Re: regarding CLUSTER and HUGE work_mem / maintenance_work_mem References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201201/92 X-Sequence-Number: 46104 On 27.01.2012 19:43, Jon Nelson wrote: > Let's say I have a 7GB table with 3-4 indices for a total of 10-12GB. > Furthermore, let's say I have a machine with sufficient memory for me > to set the work_mem and maintenance_work_mem to 20GB (just for this > session). > When I issue a CLUSTER using one of the indices, I see PostgreSQL (by > way of strace) performing an index scan which amounts to large > quantities of random I/O. > In my case, that means it takes a very, very long time. PostgreSQL is > largely at defaults, except for a 2GB shared_buffers and a few > unrelated changes. The system itself has 32GB of physical RAM and has > plenty free. > Why didn't PostgreSQL just read the table into memory (and the > interesting index) as a sequential scan, sort, and then write it out? > It seems like there would be more than enough memory for that. The > sequential I/O rate on this machine is 50-100x the random I/O rate. > > I'm using 8.4.10 (with the 'inet' de-toasting patch) on Scientific Linux 6.1. The suppport for doing a seqscan+sort in CLUSTER was introduced in version 9.1. Before that, CLUSTER always did an indexscan. See release notes: http://www.postgresql.org/docs/9.1/static/release-9-1.html#AEN107416 -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com