Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id E570D1337C84 for ; Wed, 16 Feb 2011 17:14:57 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 39694-02-7 for ; Wed, 16 Feb 2011 21:14:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gransy.com (mail.gransy.com [82.208.29.194]) by mail.postgresql.org (Postfix) with ESMTP id 005121337C5E for ; Wed, 16 Feb 2011 17:13:45 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail.gransy.com (Postfix) with ESMTP id 17A052E5A07D for ; Wed, 16 Feb 2011 22:13:42 +0100 (CET) Received: from mail.gransy.com ([127.0.0.1]) by localhost (nathalia.gransy.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id S0tZT7ETeb6f for ; Wed, 16 Feb 2011 22:13:42 +0100 (CET) Received: from [192.168.1.1] (ip-89-103-151-111.net.upcbroadband.cz [89.103.151.111]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTPSA id 006AC2E5A069 for ; Wed, 16 Feb 2011 22:13:41 +0100 (CET) Message-ID: <4D5C3E05.2070909@fuzzy.cz> Date: Wed, 16 Feb 2011 22:13:41 +0100 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101219 Lightning/1.0b3pre Thunderbird/3.1.7 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Estimating hot data size References: In-Reply-To: X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201102/419 X-Sequence-Number: 42557 Dne 16.2.2011 21:51, Chris Hoover napsal(a): > All, > > I'm trying to estimate the size of my hot data set, and wanted to get > some validation that I'm doing this correctly. > > Basically, I'm using the sum(heap_blks_read + idx_blks_read) from > pg_statio_all_tables, and diffing the numbers over a period of time (1 > hour at least). Is this a fair estimate? The reason for doing this is > we are looking at new server hardware, and I want to try and get enough > ram on the machine to keep the hot data in memory plus provide room for > growth. > > Thanks, > > Chris > > Example: > > > > *Time* > > > > *Total Blocks* > > 2011-02-16 11:25:34.621874-05 > > > > 123,260,464,427.00 > > 2011-02-16 12:25:46.486719-05 > > > > 123,325,880,943.00 > > > > To get the hot data for this hour (in KB), I'm taking: > > > (123,325,880,943.00 - 123,260,464,427.00)* 8 = 523,332,128KB > > > Correct? I doubt that, although I'm not sure what exactly you mean by hot data set. I guess it's the data set you're working with frequently, right? The first gotcha is that heap_blks_read counts only blocks not found in shared buffers, so those 500MB is actually the amount of data read from the disk (or filesystem cache). It does not say anything about how frequently the data are used. The second gotcha is that the same block may be counted repeatedly, especially if it is not frequently used. It's counted for query A, then it's removed from the cache (to be replaced by another block), and then for another query B. So the number heap_blks_read does not mean there were that many different blocks read from the disk. What I'd recommend is to measure the cache hit ratio, i.e. this heap_blks_hit / (heap_blks_read + heap_blks_hit) which means how efficient the cache is. Increase shared buffers until it stops to increase - that's the hot data set size. regards Tomas PS: The value heap_blks_hit does not actually mean the blocks were read from the disk - it might be read from filesystem cache (and there's not easy way to find out this AFAIK).