Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TEWVQ-0006fc-E3 for pgsql-admin@postgresql.org; Thu, 20 Sep 2012 02:28:44 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TEWVO-00037f-5F for pgsql-admin@postgresql.org; Thu, 20 Sep 2012 02:28:43 +0000 Received: by pbbrr13 with SMTP id rr13so3938707pbb.19 for ; Wed, 19 Sep 2012 19:28:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=sDSZqVuG1KWtxoWG6u/6LTkbKRtMI5Etdag6pigJREk=; b=BE86Of9nSu6AKdwlIlh9Xiz1a3UlzVSyW/fAbnfaWFDnMe7i3MtP1YjQFUjk1XLcrZ EV1EquoZ/pIOsJRWwzqeSAw3Ed02a71XPihWscFy8rrTzr3WSPD+366qREglhhgrG2zw fzPhRpMCeYuja06YOZg5j2N3nbAq/nu2pZVhWnEZ7X3P1GJCLZla6ZrHSZ2vK4XeJ2ti JVSc6xE8Fntwgm1rCOGc8O0dLs5izQynPVSKQ4F7RW/GHIQAoPdKLrvoclu9715WSxFU MRoC6JNFtz34PmnPgS/JIRZLtxuI8aLTYBSbd5dr/8LjiQiTS1FKRKh/TaW/NKYCEsfw onBA== Received: by 10.68.226.167 with SMTP id rt7mr2595914pbc.146.1348108121651; Wed, 19 Sep 2012 19:28:41 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id rm6sm2729181pbc.54.2012.09.19.19.28.39 (version=SSLv3 cipher=OTHER); Wed, 19 Sep 2012 19:28:40 -0700 (PDT) Message-ID: <505A7F54.2090204@ringerc.id.au> Date: Thu, 20 Sep 2012 10:28:36 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: A J CC: PG Admin Subject: Re: Postgres Cache usage References: <1348072617.30485.YahooMailNeo@web163805.mail.gq1.yahoo.com> In-Reply-To: <1348072617.30485.YahooMailNeo@web163805.mail.gq1.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnqfJyUMcXcOVEyrBIc0OPCxnj36ZNfZJBGG6XyG4s3zSc0lxGAZj70wU3mpjG3CPHeC2fQ X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/111 X-Sequence-Number: 40052 On 09/20/2012 12:36 AM, A J wrote: > Hi, > I have a read heavy application. I would want it to read from memory as > database latency has to be in low milliseconds. > The database is not too big in size and can be fully contained in memory. > > With Postgres, if I cache all the tables (by pre-emptive querying such > as select * from tables); is it assured that all subsequent queries that > have involved where clauses made up of several indexed fields will still > hit the cache (unless data is refreshed by writes) ? > > Example if my first query is select * from table1. Then if my second > query is "select * from table1 where (field1 between v1 and v2) and > (field2 between v3 and v4)"; would the second query read from the cache ? The second query will most likely get cached tuples from the heap, but the index(es) won't be in RAM so it won't have cached copies of them to use. What you want to do is "pre-warm" the caches. Search for "postgresql prewarm". See, eg: http://archives.postgresql.org/message-id/CA+TgmobRrRxCO+t6gcQrw_dJw+Uf9ZEdwf9beJnu+RB5TEBjEw@mail.gmail.com -- Craig Ringer