Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 84CEA9FBEC6 for ; Tue, 3 Apr 2007 12:23:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 59427-04-7 for ; Tue, 3 Apr 2007 12:23:22 -0300 (ADT) X-Greylist: delayed 00:22:25.868816 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 9EEDF9FC05D for ; Tue, 3 Apr 2007 12:16:16 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail.mnc.ch (62-2-77-205.static.cablecom.ch [62.2.77.205]) by svr4.postgresql.org (Postfix) with ESMTP id 6AE6D5AF882 for ; Tue, 3 Apr 2007 14:53:43 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by mail.mnc.ch (Postfix) with ESMTP id 8C9F7A829A; Tue, 3 Apr 2007 16:53:40 +0200 (CEST) Received: from mail.mnc.ch ([127.0.0.1]) by localhost (mail.test.lan [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id 23667-08; Tue, 3 Apr 2007 16:53:39 +0200 (CEST) Received: from meuh.mnc.lan (62-2-77-204.static.cablecom.ch [62.2.77.204]) by mail.mnc.ch (Postfix) with ESMTP id 81B09A82BE; Tue, 3 Apr 2007 16:53:39 +0200 (CEST) Received: by meuh.mnc.lan (Postfix, from userid 1000) id 86A1E1836AD; Tue, 3 Apr 2007 16:53:39 +0200 (CEST) To: Jean Arnaud Cc: PostgreSQL Performance Subject: Re: Cache hit ratio References: <461260C4.8050508@inrialpes.fr> X-Hashcash: 1:20:070403:jean.arnaud@inrialpes.fr::+M+lf5OU0ZbuAL4G:00000000000000000000000000000000000003bVR X-Hashcash: 1:20:070403:pgsql-performance@postgresql.org::xI/Kt5g9vgVsPFE0:00000000000000000000000000000C1HQ From: Guillaume Cottenceau Date: 03 Apr 2007 16:53:39 +0200 In-Reply-To: <461260C4.8050508@inrialpes.fr> Message-ID: <87zm5ppkzw.fsf@meuh.mnc.lan> Lines: 64 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: amavisd-new at mnc.ch X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.136 tagged_above=0 required=5 tests=BAYES_50=0.001, FORGED_RCVD_HELO=0.135 X-Spam-Level: X-Archive-Number: 200704/17 X-Sequence-Number: 23894 Jean Arnaud writes: > Hi > > Is there a way to get the cache hit ratio in PostGreSQL ? When you activate: stats_block_level = true stats_row_level = true you will get global statistics, per table and per index, about read disk blocks and saved reads thanks to buffers. That said, I'd like to add that however, I am not sure what performance gain we should expect by increasing the buffers to increase the cache hit ratio. For example, for a bunch of given heavy SQL queries, with -B 1000 (pg 7.4) the difference is: select * from pg_statio_user_indexes where indexrelname = 'pk_themes'; relid | indexrelid | schemaname | relname | indexrelname | idx_blks_read | idx_blks_hit ----------+------------+------------+---------+--------------+---------------+-------------- 77852514 | 86437474 | public | themes | pk_themes | 220 | 0 select * from pg_statio_user_indexes where indexrelname = 'pk_themes'; relid | indexrelid | schemaname | relname | indexrelname | idx_blks_read | idx_blks_hit ----------+------------+------------+---------+--------------+---------------+-------------- 77852514 | 86437474 | public | themes | pk_themes | 275 | 0 which shows the index on primary keys is used, but is always read from disk. If I then use -B 20000 (kernel reports the postmaster process enlarges from 22M to 173M of RSS), the difference is: select * from pg_statio_user_indexes where indexrelname = 'pk_themes'; relid | indexrelid | schemaname | relname | indexrelname | idx_blks_read | idx_blks_hit ----------+------------+------------+---------+--------------+---------------+-------------- 77852514 | 86437474 | public | themes | pk_themes | 55 | 110 select * from pg_statio_user_indexes where indexrelname = 'pk_themes'; relid | indexrelid | schemaname | relname | indexrelname | idx_blks_read | idx_blks_hit ----------+------------+------------+---------+--------------+---------------+-------------- 77852514 | 86437474 | public | themes | pk_themes | 55 | 165 which shows postmaster manages to keep the index in buffers. But, the clock time used for the request is actually identical when using -B 1000 or -B 20000. I suppose the kernel is bringing the performance difference thanks to filesystem caching. In conclusion, I guess that using postmaster cache rather than kernel cache is probably better in the long run, because postmaster might be able to make better caching decisions than the kernel because it has additional information, but I am not sure in which circumstances and the amount of better decisions it can take. -- Guillaume Cottenceau, MNC Mobile News Channel SA, an Alcatel-Lucent Company Av. de la Gare 10, 1003 Lausanne, Switzerland - direct +41 21 317 50 36