X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EDC93DA9E6 for ; Fri, 21 Oct 2005 18:44:41 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02134-05 for ; Fri, 21 Oct 2005 21:44:38 +0000 (GMT) Received: from mailbox.samurai.com (mailbox.samurai.com [205.207.28.82]) by svr1.postgresql.org (Postfix) with ESMTP id 2AAAEDA9E9 for ; Fri, 21 Oct 2005 18:44:40 -0300 (ADT) Received: from localhost (mailbox.samurai.com [205.207.28.82]) by mailbox.samurai.com (Postfix) with ESMTP id DDD5923989E; Fri, 21 Oct 2005 17:44:42 -0400 (EDT) Received: from mailbox.samurai.com ([205.207.28.82]) by localhost (mailbox.samurai.com [205.207.28.82]) (amavisd-new, port 10024) with LMTP id 67140-01-8; Fri, 21 Oct 2005 17:44:41 -0400 (EDT) Received: from [192.168.1.103] (d226-86-55.home.cgocable.net [24.226.86.55]) by mailbox.samurai.com (Postfix) with ESMTP id 8E3BB239893; Fri, 21 Oct 2005 17:44:41 -0400 (EDT) Subject: Re: What gets cached? From: Neil Conway To: Martin Nickel Cc: pgsql-performance@postgresql.org In-Reply-To: References: Content-Type: text/plain Date: Fri, 21 Oct 2005 17:44:47 -0400 Message-Id: <1129931087.19971.12.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mailbox.samurai.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200510/302 X-Sequence-Number: 15070 On Fri, 2005-21-10 at 07:34 -0500, Martin Nickel wrote: > Let's say I do the same thing in Postgres. I'm likely to have my very > fastest performance for the first few queries until memory gets filled up. No, you're not: if a query doesn't hit the cache (both the OS cache and the Postgres userspace cache), it will run slower. If the caches are empty when Postgres starts up (which is true for the userspace cache and might be true of the OS cache), the first queries that are run should be slower, not faster. > The only time Postgres seems to take advantage of cached data is when I > repeat the same (or substantially the same) query. Caching is done on a page-by-page basis -- the source text of the query itself is not relevant. If two different queries happen to hit a similar set of pages, they will probably both benefit from the same set of cached pages. > I don't know of any way to view what is actually cached at any point > in time, but it seems like "most recently used" rather than "most > frequently used". The cache replacement policy in 7.4 and older releases is simple LRU. The policy in 8.0 is ARC (essentially a version of LRU modified to try to retain hot pages more accurately). The policy in 8.1 is a clock-based algorithm. -Neil