简体   繁体   中英

Can we ask postgres to use caching for specific tables?

我们可以要求postgres对特定表使用缓存,并且根本不用于几个表吗?

In order to read data and operate on it, PostgreSQL has to bring it into its cache. And doing that will also put it temporarily 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.

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.

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 (eg 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM