Can we ask postgres to use caching for specific tables?
Can we ask postgres to use caching for specific table开发者_Go百科s and don't use it for few tables at all?
No, you cannot control what is going to be cached.
But if that is a frequently accessed table, it will be cached anyway. If it's not accessed frequently it will not be cached.
So I don't see a reason for trying to control this.
In order to read data and operate on it, PostgreSQL has to bring it into its cache. And doing that will temporarily put it in the operating system cache too. You can find an exact description of how that data will eventually be evicted from the database's cache once processes stop using it in my Inside the PostgreSQL Buffer Cache talk.
You can get faster eviction from cache by reducing the size of the shared_buffers parameter, which may have performance downsides. PostgreSQL always reads using the OS cache, and you can't keep that from being polluted when you access large amounts of data.
There is an optimization for sequential scans that keeps the database's own shared_buffers cache from being taken over by that data. Tables that are larger than (shared_buffers / 4) are limited to only using a small amount of memory on the database's side. Those will still hammer the operating system cache though, but those tend to hold onto infrequently used data for less time than the database will.
You can't do that. PostgreSQL does a really good job maintaining it itself. In fact, I can't think of a case where you'd like to modify this behavior.
If you see an issue (such as a table using too much cache), it probably means that table is used ineffectively (e.g. there are queries with seq scan). If some tables use little cache, it's either because so little is optimal, or because total cache size is too small. Either way, PG is doing the best it can.
What exactly made you ask this question?
PostgreSQL and the operating system will do the caching much better. Data you don't use, won't be in the cache, data you do use, is in the cache. You don't want to fight your database and the operating system, there is no need for.
Why not using pgfincore to store the tables in OS cache?
The flowing blog show how to use it. http://francs3.blog.163.com/blog/static/4057672720107541611270/
精彩评论