X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3AC7D528E0 for ; Mon, 13 Jun 2005 11:51:43 -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 40617-03 for ; Mon, 13 Jun 2005 14:51:39 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9349152889 for ; Mon, 13 Jun 2005 11:51:38 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j5DEpd6V019819; Mon, 13 Jun 2005 10:51:39 -0400 (EDT) To: Jona Cc: pgsql-performance@postgresql.org Subject: Re: How to enhance the chance that data is in disk cache In-reply-to: <42AD844F.3070700@oismail.com> References: <579bc853ef3957c736c2773f13c444f7@implements.be> <42ACF2DD.8090409@paradise.net.nz> <42AD49BF.7050706@paradise.net.nz> <42AD844F.3070700@oismail.com> Comments: In-reply-to Jona message dated "Mon, 13 Jun 2005 15:04:15 +0200" Date: Mon, 13 Jun 2005 10:51:39 -0400 Message-ID: <19818.1118674299@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.045 tagged_above=0 required=5 tests=AWL, NORMAL_HTTP_TO_IP X-Spam-Level: X-Archive-Number: 200506/291 X-Sequence-Number: 12928 Jona writes: > I have a query (please refer to > http://213.173.234.215:8080/get_content_plan.htm for the query as well > as query plan) that is slow when it's run the first time and fast(ish) > on all successive runs within a reasonable time period. > This leads me to suspect that when the query is first run, all used data > have to be fetched from the disk where as once it has been run all data > is available in the OS's disk cache. Sounds like that to me too. > Is there anway to either enhance the chance that the data can be found > in the disk cache or allowing the database to fetch the data faster? Run the query more often? Also, that pile of INNER JOINs is forcing a probably-bad join order; you need to think carefully about the order you want things joined in, or else convert the query to non-JOIN syntax. See the "Performance Tips" chapter of the manual. regards, tom lane