Prewarming caches with pg_prewarm

When PostgreSQL operates normally, it tries to cache important data. The shared_buffers variable is important as it defines the size of the cache managed by PostgreSQL. The problem now is this: if you restart the database server, all the cache managed by PostgreSQL will be lost. Maybe the operating system will still have some data to reduce the impact on disk wait, but in many cases, this won't be enough. The solution to the problem is called the pg_prewarm extension:

test=# CREATE EXTENSION pg_prewarm;CREATE EXTENSION

The extension deploys a function that allows us to explicitly prewarm the cache whenever it is needed:

test=# \xExpanded display is on. test=# \df *prewa*List of functions-[ RECORD 1 ]-------+-------------------------------------------------------- ...

Get Mastering PostgreSQL 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.