Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YFBOV-0005tA-Ek for pgsql-performance@arkaria.postgresql.org; Sun, 25 Jan 2015 00:49:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YFBOU-0005oi-EA for pgsql-performance@arkaria.postgresql.org; Sun, 25 Jan 2015 00:49:38 +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 1YFBOS-0005o8-B0 for pgsql-performance@postgresql.org; Sun, 25 Jan 2015 00:49:36 +0000 Received: from mail-wg0-f54.google.com ([74.125.82.54]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YFBOJ-0002rW-Oc for pgsql-performance@postgresql.org; Sun, 25 Jan 2015 00:49:35 +0000 Received: by mail-wg0-f54.google.com with SMTP id b13so3496361wgh.13 for ; Sat, 24 Jan 2015 16:49:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:organization:user-agent :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=Eq18vrYswRkRONOw2nftC15UHTjWsufqKcvF9FMCuyk=; b=TJ/wTS/T32+8bMcVTZbmFPjRWAX9DAqEHE3LW8rJn7312Vuspuhy7e+XpEVuoT0xI3 v3WRPI/3hlRrBUJ1CpfpqZECRILmYCB815vTHfcYOyVyZH6PDiMCeglOTyuM6pncpNCJ kYgxvZbTDzTs5nDW8PAYrX0z/zyRy31EWJJ6GZTepy8ZK+2dqMYc+M+vtpOe8cPuaz/e 4+VXzpvhb2Zy3hqhLG6cbvbLG3/fVXhHAkxkipIH+HFPxhQiyjlPm+eDCk2MuyZgi5Ja 4EW1BmxUy/B8bMGlQAuZQ0DVlvYX3+eBoiNtnP9IHXOWJZ6zgTIhZiFbDy7ewg98aVc7 2a0A== X-Gm-Message-State: ALoCoQmwy0ZtQ65zrZweMiiJEGk4UxrWzG9huh/iKzwJXB5Z4eoGpAuGPP3+J4aDg24qUNsGP2uRwl3Hdb9Fd5DBC/bIB19x/bIhhbPelfTV09VM3fCVEe8rBJWAiCIRw71nfY4mXqU+FH48B/CH1VAVfzgNmpi/Ut0Dg1Enz85sDXQTaY27cSykQiC3HnNJWDQ5XWS8STwp X-Received: by 10.194.82.97 with SMTP id h1mr29571629wjy.136.1422146966568; Sat, 24 Jan 2015 16:49:26 -0800 (PST) Received: from [192.168.1.163] (ip-78-45-139-138.net.upcbroadband.cz. [78.45.139.138]) by mx.google.com with ESMTPSA id qg11sm7760451wic.17.2015.01.24.16.49.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Jan 2015 16:49:25 -0800 (PST) Message-ID: <54C43D93.9030608@2ndquadrant.com> Date: Sun, 25 Jan 2015 01:49:23 +0100 From: Tomas Vondra Organization: 2ndQuadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: How to tell ANALYZE to collect statistics from the whole table? References: <1422142399144-5835339.post@n5.nabble.com> In-Reply-To: <1422142399144-5835339.post@n5.nabble.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) 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 Hi, On 25.1.2015 00:33, AlexK987 wrote: > 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? I don't think there's an official way to do that - at least I can't think of one. The only thing you can do is increasing statistics target (either globally by setting default_statistics_target, or per column using ALTER TABLE ... SET STATISTICS). As you noticed, this however controls two things - sample size and how detailed the statistics (MCV list / histogram) will be. The statistics target is used as upper bound for number of MCV items / histogram bins, and the number of sampled rows is (300 * statistics_target). With default_statistics_target = 10000 (which si the max allowed value since 9.0), this produces very detailed stats and uses sample of ~3M rows. It's a bit more complicated though, because there's an algorithm that decides how many MCV items / histogram buckets to actually create, based on the data. So you may not get more detailed stats, even when using larger sample. That being said, I really doubt increasing the statistics target above 10000 (or even sampling the whole table) will help you in practice. Might be worth showing an example of a bad estimate with your data, or maybe a test case to play with. -- Tomas Vondra http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance