Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Low Postgres Cache Hit Ratio - data size or something else?

I've just upgraded my Heroku postgres database from the Kappa plan (800MB RAM, postgres 9.1) to the Ronin plan (1.7GB RAM, postgres 9.2), but performance has degraded.

Following the guide here, I checked and the cache hit rate is even lower than it was with our Kappa database (now ~57%, previously ~69%). Our app design should be decently ok, as we've seen a cache hit rate of ~99% before.

The recommendation is that the data set should be able to fit into memory, which shouldn't be a problem now - our data size is 1.27GB (at least most of it should fit).

Is the low cache hit rate due to the data size, or is there something else I can look into? Or is it simply a case of the database cache not fully warmed up? (it's been almost 2 days)

like image 985
Daniel Avatar asked May 29 '13 05:05

Daniel


People also ask

What is cache hit ratio Postgres?

Cache hit ratio is a metric that measures the efficiency of key retrieval in a database. Cache hit ratio is the ratio of key hits against the total number of key hits and misses.

How do you increase hit ratio in cache?

To increase your cache hit ratio, you can configure your origin to add a Cache-Control max-age directive to your objects, and specify the longest practical value for max-age .

Does postgresql cache results?

It will execute it each time. It will cache the data it needs to do the execution (assuming that is small enough to stay in cache), but not the results.

What are the read/write ratio of cache memory?

Consider a cache memory hit ratios for read and write operations are 80% and 90% respectively. If there is a miss then 2 word block is to be through from main memory to cache.


1 Answers

If you have plenty of memory and are not running much else on the db, one thing that may change is the shared_buffers. What the shared buffers do is they cache frequently used data so that it maximizes throughout when not all of the database will fit in memory.

Unfortunately this cache does not perform as well as he OS cache. If your data will easily fit in memory, make sure that effective_cache_size is high enough, and then try reducing shared_buffers

Note that this is not a magic bullet. The appropriate size of shared_buffers depends on how much data you have, how much space it takes up, your types of queries, how much memory is going towards things like sorts and the like. You can expect to play around with this from time to time to find the sweet spot for your current setup and database.

like image 159
Chris Travers Avatar answered Oct 28 '22 23:10

Chris Travers