Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YFFX9-0000Fv-Ac for pgsql-performance@arkaria.postgresql.org; Sun, 25 Jan 2015 05:14:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YFFX7-0006FN-Du for pgsql-performance@arkaria.postgresql.org; Sun, 25 Jan 2015 05:14:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YFFX6-0006FG-Bw for pgsql-performance@postgresql.org; Sun, 25 Jan 2015 05:14:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YFFX2-0007Yp-Ks for pgsql-performance@postgresql.org; Sun, 25 Jan 2015 05:14:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t0P5Ef44018231; Sun, 25 Jan 2015 00:14:41 -0500 From: Tom Lane To: AlexK987 cc: pgsql-performance@postgresql.org Subject: Re: How to tell ANALYZE to collect statistics from the whole table? In-reply-to: <1422142399144-5835339.post@n5.nabble.com> References: <1422142399144-5835339.post@n5.nabble.com> Comments: In-reply-to AlexK987 message dated "Sat, 24 Jan 2015 16:33:19 -0700" Date: Sun, 25 Jan 2015 00:14:41 -0500 Message-ID: <18230.1422162881@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org AlexK987 writes: > The documentation states that "The extent of analysis can be controlled by > adjusting the default_statistics_target configuration variable". It looks > like I can tell Postgres to create more histograms with more bins, and more > distinct values. This implicitly means that Postgres will use a larger > random subset to calculate statistics. > However, this is not what I want. My data may be quite skewed, and I want > full control over the size of the sample. I want to explicitly tell Postgres > to analyze the whole table. How can I accomplish that? You can't, and you wouldn't want to if you could, because that would result in slurping the entire table into backend local memory. All the rows constituting the "random sample" are held in memory while doing the statistical calculations. In practice, the only stat that would be materially improved by taking enormously large samples would be the number-of-distinct-values estimate. There's already a way you can override ANALYZE's estimate of that number if you need to. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance