pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedPostgres Cache usage
3+ messages / 3 participants
[nested] [flat]
* Postgres Cache usage
@ 2012-09-19 16:36 A J <s5aly@yahoo.com>
0 siblings, 2 replies; 3+ messages in thread
From: A J @ 2012-09-19 16:36 UTC (permalink / raw)
To: pgsql-admin
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 ?
Thanks.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Postgres Cache usage
@ 2012-09-19 17:38 Steve Crawford <scrawford@pinpointresearch.com>
parent: A J <s5aly@yahoo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Steve Crawford @ 2012-09-19 17:38 UTC (permalink / raw)
To: pgsql-admin
On 09/19/2012 09: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 ?
>
> Thanks.
Probably, mostly. But the planner won't use an index for the first query
but hopefully will on the second and the index may not be cached. If you
have enough RAM and nothing contending for it then the OS will probably
cache appropriately.
But there are other optimizations you may want to consider like turning
off atime on your disk (for Linux, in any case) to avoid requiring a
write for every read.
For simple read queries the connection setup time will become an issue
so connection-pooling and persistent connections will be useful.
Cheers,
Steve
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Postgres Cache usage
@ 2012-09-20 02:28 Craig Ringer <ringerc@ringerc.id.au>
parent: A J <s5aly@yahoo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Craig Ringer @ 2012-09-20 02:28 UTC (permalink / raw)
To: A J <s5aly@yahoo.com>; +Cc: pgsql-admin
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.g...
--
Craig Ringer
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2012-09-20 02:28 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-09-19 16:36 Postgres Cache usage A J <s5aly@yahoo.com>
2012-09-19 17:38 ` Steve Crawford <scrawford@pinpointresearch.com>
2012-09-20 02:28 ` Craig Ringer <ringerc@ringerc.id.au>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox