pg_prewarm
prewarm relation data
pg_prewarm : prewarm relation data
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5890 | pg_prewarm | pg_prewarm | 1.2 |
ADMIN | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sLd-- | No | Yes | Yes | Yes | no | no |
| Relationships | |
|---|---|
| Need By | pgcozy |
| See Also | pg_buffercache pgfincore pgcozy pg_cooldown |
Packages
| PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|
| 1.2 | 1.2 | 1.2 | 1.2 | 1.2 |
This is a built-in contrib extension ship with the PostgreSQL kernel
Install
Config this extension to shared_preload_libraries:
Create this extension with:
Usage
The pg_prewarm extension provides functions to load relation data into the operating system buffer cache or PostgreSQL buffer cache, reducing I/O latency for subsequent queries.
Prewarm a Relation
Function Signature
Returns the number of blocks prewarmed.
| Parameter | Description |
|---|---|
mode |
prefetch (async OS), read (sync OS), or buffer (PG cache) |
fork |
Relation fork to prewarm (e.g., main, fsm, vm) |
first_block |
First block number (default: 0) |
last_block |
Last block number (default: last block of relation) |
Autoprewarm
When loaded via shared_preload_libraries, autoprewarm periodically saves the list of buffers in the shared buffer cache to disk and restores them on restart.
GUC Parameters
| Parameter | Default | Description |
|---|---|---|
pg_prewarm.autoprewarm |
true |
Enable autoprewarm background worker |
pg_prewarm.autoprewarm_interval |
300s |
Interval between autoprewarm.blocks file updates (0 = dump only at shutdown) |
Buffer state is saved to autoprewarm.blocks in the data directory. After restart, two background workers reload the saved buffers.