Book Image

Learning Heroku Postgres

By : Patrick Rafael de Oliveira Espake
Book Image

Learning Heroku Postgres

By: Patrick Rafael de Oliveira Espake

Overview of this book

Table of Contents (17 chapters)
Learning Heroku Postgres
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Keyword List
Index

Data caching


Generally, for most applications, only one piece of data is frequently accessed. Postgres monitors the accessed data and places it in a cache to improve the performance of your queries. If your application is well designed, it is possible that 99 percent of the queries are cached.

You can find the cache rate of your database with the following SQL query:

$ heroku pg:psql --app your-app-name
SELECT sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) as percentage, sum(heap_blks_hit) as quantity_hit, sum(heap_blks_read) as quantity_read FROM pg_statio_user_tables;
      percentage       | quantity_hit    | quantity_read 
-----------------------+-----------------+---------------
0.99999826000612665185 |   4024719812    |          7003
(1 row)

In this example, the application and the database are optimized with 99.99 percent of cache. If your percentage is below that, you should consider optimizing your application or change your database plan to a higher one that offers...