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-r | No | Yes | Yes | Yes | yes | no |
| Relationships | |
|---|---|
| Need By | pgcozy |
| See Also | pg_buffercache pgfincore pgcozy pg_cooldown |
Packages
| PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|
| 1.2 | 1.2 | 1.2 | 1.2 | 1.2 |
This contrib extension ships with PostgreSQL.
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.