postgres pg_prewarm - ghdrako/doc_snipets GitHub Wiki

Configuration

# postgresql.conf
shared_preload_libraries = 'pg_prewarm'

pg_prewarm.autoprewarm = true
pg_prewarm.autoprewarm_interval = 300s

Usage

pg_prewarm(regclass, mode text default 'buffer', fork text default 'main',
           first_block int8 default null,
           last_block int8 default null) RETURNS int8
$ SELECT pg_prewarm('plans');

prewarm just the last 1000 pages

SELECT pg_prewarm(
    'plans',
    first_block := (
        SELECT pg_relation_size('plans') / current_setting('block_size')::int4 - 1000
    )
);