Skip to content

pgcozy

Pre-warming shared buffers according to previous pg_buffercache snapshots for PostgreSQL.

pgcozy · Pre-warming shared buffers according to previous pg_buffercache snapshots for PostgreSQL.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
5190pgcozypgcozy1.0ADMINPostgreSQLSQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
----d--NoNoNoYesnono

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.019 18 17 16 15pgcozypg_buffercache, pg_prewarm
RPMPIGSTY1.019 18 17 16 15pgcozy_$v-
DEBPIGSTY1.019 18 17 16 15postgresql-$v-pgcozy-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el8.aarch64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el10.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el10.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d12.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d12.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d13.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d13.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u22.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u22.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u24.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u24.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u26.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u26.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0

Source

pig build pkg pgcozy;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pgcozy;		# install by package name

pig install pgcozy -v 19;   # install for PG 19
pig install pgcozy -v 18;   # install for PG 18
pig install pgcozy -v 17;   # install for PG 17
pig install pgcozy -v 16;   # install for PG 16
pig install pgcozy -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION pgcozy CASCADE; -- requires pg_buffercache, pg_prewarm

Usage

pgcozy: Pre-warming shared buffers according to previous pg_buffercache snapshots for PostgreSQL.

pgcozy snapshots the current shared buffer state and can later restore (pre-warm) buffers from those snapshots. Requires pg_buffercache and pg_prewarm extensions.

Initialize

SELECT pgcozy_init();

Creates the pgcozy schema with a snapshots table and the cozy_type type.

Take a Snapshot

-- Snapshot buffer pages with usagecount >= 3 (popularity 1-5)
SELECT pgcozy_snapshot(3);

-- Snapshot all buffered pages (popularity = 0)
SELECT pgcozy_snapshot(0);

Snapshots are stored as JSONB in pgcozy.snapshots with columns: id, snapshot_date, snapshot. Each entry contains table_name, block_no, and popularity.

Warm from a Snapshot

-- Warm from a specific snapshot by ID
SELECT pgcozy_warm(1);

-- Warm from the latest snapshot
SELECT pgcozy_warm(0);

Review Snapshots

SELECT id, snapshot_date FROM pgcozy.snapshots;

Snapshots are stored in JSONB and can be reviewed, backed up, or transferred between servers.

Table reader