Upon the restart of a database cluster, it may take some time to load the whole of the cache into the PostgreSQL buffer cache or the OS buffer cache. Sometimes, we may wish to load certain tables into the cache on-demand before performing some special reporting tasks. To help cache a table or a specific set of pages to either the OS cache or the database buffer cache (shared buffers), there exists an extension called pg_prewarm.
pg_prewarm is a function that can take five arguments:
pg_prewarm(regclass, mode text default 'buffer', fork text default 'main',
first_block int8 default null, last_block int8 default null) RETURNS int8
Let's discuss each of these arguments in detail:
- regclass: Fully qualified table name (schemaname.tablename).
- mode: You can choose any of the three prewarming methods:
- prefetch: Asynchronous prefetch requests to the OS. Cached in the OS.
- read: Synchronous prefetch. Cached in the OS.
- buffer: Reads...